jQWidgets Forums
jQuery UI Widgets › Forums › Chart › line chart
Tagged: beforeLoadComplete, chart, data adapter, dataadapter, datafield, incremental, jqxChart, JSONP, valueAxis, x-axis
This topic contains 6 replies, has 2 voices, and was last updated by Dimitar 10 years, 11 months ago.
-
Authorline chart Posts
-
I would like to create line chart that will get data from datatype jsonp but the issue is that I just retrieve the Y Axis data and I would like that X Axis value will grow in 1 according to each point.
Can you give me an example how to do that?
Hello lev_povolotsky,
Here is an example on how to achieve this (notice the beforeLoadComplete data dapter callback function):
<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /> <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script> <script type="text/javascript" src="../../jqwidgets/jqxchart.js"></script> <script type="text/javascript"> $(document).ready(function () { // prepare the data var source = { datatype: "json", datafields: [ { name: 'max' } ], url: '../sampledata/weather_geneva.txt' }; var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, beforeLoadComplete: function (records) { for (var i = 0; i < records.length; i++) { records[i].xAxis = i; }; return records; }, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } }); // prepare jqxChart settings var settings = { title: "Weather in Geneva, Switzerland", description: "Climatological Information about Geneva", enableAnimations: true, showLegend: true, padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 90, top: 0, right: 0, bottom: 10 }, source: dataAdapter, categoryAxis: { text: 'Category Axis', textRotationAngle: 0, dataField: 'xAxis', showTickMarks: true, tickMarksInterval: 1, tickMarksColor: '#888888', unitInterval: 1, showGridLines: true, gridLinesInterval: 3, gridLinesColor: '#888888', axisSize: 'auto' }, colorScheme: 'scheme05', seriesGroups: [ { type: 'line', //useGradient: false, valueAxis: { unitInterval: 5, displayValueAxis: true, description: 'Temperature [C]', //descriptionClass: 'css-class-name', axisSize: 'auto', tickMarksColor: '#888888' }, series: [ { dataField: 'max', displayText: 'Max Temperature' } ] } ] }; // setup the chart $('#jqxChart').jqxChart(settings); }); </script> </head> <body class='default'> <div id='jqxChart' style="width: 850px; height: 400px"> </div> </body> </html>
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/I made exactly the same as you made from the only thing is that I take the data from jsonp
but the only Axis is filled in really strange, please tell me what do you recommend me to do?
$(document).ready(function () { // prepare the data var source = { dataType: "jsonp", datafields: [ { name: 'max' } ], url: "http://localhost:9998/test" }; var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, beforeLoadComplete: function (records) { for (var i = 0; i < records.length; i++) { records[i].xAxis = i; console.log(records[i].xAxis); console.log(records[i].yAxis); }; return records; }, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } }); // prepare jqxChart settings var settings = { title: "Weather in Geneva, Switzerland", description: "Climatological Information about Geneva", enableAnimations: true, showLegend: true, padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 90, top: 0, right: 0, bottom: 10 }, source: dataAdapter, categoryAxis: { text: 'Category Axis', textRotationAngle: 0, dataField: 'xAxis', showTickMarks: true, tickMarksInterval: 50, tickMarksColor: '#888888', unitInterval: 50, showGridLines: true, gridLinesInterval: 50, gridLinesColor: '#888888', axisSize: 'auto' }, colorScheme: 'scheme05', seriesGroups: [ { type: 'line', //useGradient: false, valueAxis: { unitInterval: 5, displayValueAxis: true, description: 'Temperature [C]', //descriptionClass: 'css-class-name', axisSize: 'auto', tickMarksColor: '#888888' }, series: [ { dataField: 'max', displayText: 'Max Temperature' } ] } ] };
Hi lev_povolotsky,
Does this mean the x-axis is not populated? And are you sure the values in your data source correspond to the chart settings (such as unitInterval)?
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Seems you are right I get from jsonp a lot of big numbers this is the results the only diffrent is instead of null I have a callback
null({"totalrecords":302,"allPoints":[27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27726312,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,27041040,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,26355672,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,25669456,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24984232,24177928,21879984,20267376,18923536,17310928,15698320,13386912,11774304,9463040,8119200,4450880,61803936,53742576,45681216,37619816,29558456,22840656,10748608,10748608,10748608,10748608,10748608,10748608]});
anyone that can help me
Hi lev_povolotsky,
You should adjust the valueAxis settings to be appropriate for your data. You can find the available properties in the jqxChart API Documentation.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.