jQWidgets Forums
jQuery UI Widgets › Forums › Chart › Chart data format?
This topic contains 6 replies, has 2 voices, and was last updated by jondecker76 11 years, 10 months ago.
-
AuthorChart data format? Posts
-
I can’t find any documentation on how chart data is to be presented. I’m trying to make a chart with 3 series from JSON data for my wind turbine.
I tried using the Area Spline demo chart for an example, which says it grabs its data from ../sampledata/homeprices.txt – but navigating to that path with the web browser shows it doesn’t exist (I wanted to see it to get an idea of how the data should be presented). I’m currently building the dataset with PHP as a multidimensional array, which doesn’t seem to be the correct way to do it. Here is the part of my code that generates the JSON data:
$query = "SELECT * FROM stats WHERE fk_turbine=1 ORDER BY timestamp DESC LIMIT 100;";$result=mysql_query($query)or die('Query failed: ' . mysql_error());$windspeed=array();$rpm=array();$kw=array();while($line=mysql_fetch_array($result, MYSQL_ASSOC)) { array_push($windspeed, $line["windspeed"]); array_push($rpm, $line["rpm"]); array_push($kw , $line["kw"]); }echo json_encode(array($windspeed,$rpm,$kw));
Any pointers?
Thanks!
Hello jondecker76,
Here is the correct link to the file homeprices.txt:
http://www.jqwidgets.com/jquery-widgets-demo/demos/sampledata/homeprices.txt
However, its data format is TSV.The file weather_geneva.txt from the demo Negative Values may be more helpful to you, its data is in JSON format:
http://www.jqwidgets.com/jquery-widgets-demo/demos/sampledata/weather_geneva.txtYou can also find all demos and sample data files in the jQWidgets download package.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thank you for your reply.
Hmm.. That didn’t help me as much as I thought it would unfortunately. Perhaps if I describe a bit more someone can help me out a little.
I have a small PHP daemon that runs and logs windspeed, RPM and Kilowatts from my wind turbine every 10 seconds, storing each with a Unix timestamp.
I would like to display the data as 3 series just like the area spline series demo, but with “Windspeed”,” RPM” and “KW” instead of “Interest Rate”, “Building Cost Index” and “Real Home Price Index”. (see: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxchart/index.htm#demos/jqxchart/javascript_chart_areaspline_series.htm)
The problem I am having is that all examples that I see, the X-axis contains known values, where my X-axis will be my Unix timestamp (which will constantly change). I’m basically trying to build a trend of values over time, and have it update once each minute. I’m having a hard time visualizing how such data can be presented…
Thanks again
I’m still getting absolutely nowhere with this. I have a php script returning JSON data. Here is the script’s output:
[{"windspeed":"4","rpm":"0","kw":"0"},{"windspeed":"4","rpm":"0","kw":"0"},{"windspeed":"4","rpm":"0","kw":"0"},{"windspeed":"4","rpm":"0","kw":"0"},{"windspeed":"4","rpm":"0","kw":"0"},{"windspeed":"5","rpm":"0","kw":"0"},{"windspeed":"5","rpm":"0","kw":"0"},{"windspeed":"5","rpm":"0","kw":"0"},{"windspeed":"4","rpm":"0","kw":"0"},{"windspeed":"4","rpm":"0","kw":"0"}]
I’m trying to get this data to display as 3 series in a stacked spline chart. The data is the last 10 logged readings from the wind turbine (values are logged to MySQL every 10 seconds by a daemon script) . I’ve tried to bind the data to the chart, but the chart just comes up blank…
Here is the code I’m trying to use to set up the chart:
// prepare the data var source ={ datatype: "json", datafields: [{ name: 'windspeed' },{ name: 'rpm' },{ name: 'kw' }], url: 'trenddata.php' }; var settings = { title: "Trend", description: "Logged every 10 seconds", padding: { left: 5, top: 5, right: 5, bottom: 5 }, titlePadding: { left: 90, top: 0, right: 0, bottom: 10 }, source: source, colorScheme: 'scheme01', seriesGroups: [ { type: 'stackedsplinearea', valueAxis: { minValue: 0, maxValue: 2000, unitInterval: 10, description: 'Value' }, series: [ { dataField: 'windspeed', displayText: 'Windspeed'}, { dataField: 'rpm', displayText: 'RPM'}, { dataField: 'kw', displayText: 'KW'} ] } ] }; // select the chartContainer DIV element and render the chart. $('#trendDash').jqxChart(settings);
I’ve even tried a full http URL for the source URL with no luck.
What am I doing wrong?
Adding to previous post..
I just added “timestamp” to the JSON data, thinking maybe this would help. Here is the JSON data now:
[{"timestamp":"1370876348","windspeed":"4","rpm":"0","kw":"0"},{"timestamp":"1370876338","windspeed":"4","rpm":"0","kw":"0"},{"timestamp":"1370876328","windspeed":"4","rpm":"0","kw":"0"},{"timestamp":"1370876318","windspeed":"4","rpm":"0","kw":"0"},{"timestamp":"1370876308","windspeed":"4","rpm":"0","kw":"0"},{"timestamp":"1370876298","windspeed":"5","rpm":"0","kw":"0"},{"timestamp":"1370876288","windspeed":"5","rpm":"0","kw":"0"},{"timestamp":"1370876278","windspeed":"5","rpm":"0","kw":"0"},{"timestamp":"1370876268","windspeed":"4","rpm":"0","kw":"0"},{"timestamp":"1370876258","windspeed":"4","rpm":"0","kw":"0"}]
Still just a blank chart though
Hi jondecker76,
The issue comes from the fact that you do not use data adapter after defining the source variable. Please check some of the demos, such as Column Series to see how to implement data adapter.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks very much. I’ve used the dataAdapter and now have it working
-
AuthorPosts
You must be logged in to reply to this topic.