Needed example to download jqplot with multiple series, date based data from json file

Search and cannot find exactly what I am looking for. You need to load several episodes into one jqplot, with each episode coming from its own data file.

An example here http://www.jqplot.com/tests/data-renderers.php shows how to load a series from a file, but when I convert the file to date data, then it stops working, maybe just a formatting problem, but cannot solve. What am I doing wrong?

Here are the data in the txt file: [["7/11/2011 04:00:00 am", 85.0], ["7/12/2011 04:00:00 AM", 87.4], ["07/13/2011 04: 00:00 AM ", 90.0]]

Here is the code:

<script class="code" type="text/javascript">$(document).ready(function(){ var line = [ ]; var ajaxDataRenderer = function(url, plot) { var ret = null; $.ajax({ // have to use synchronous here, else returns before data is fetched async: false, url: url, dataType:'json', success: function(data) { ret = data; } }); return ret; }; var jsonurl = "./jsondata1.txt"; plo12 = $.jqplot('chart2', jsonurl,{ title: 'AJAX JSON Data Renderer', dataRenderer: ajaxDataRenderer, axes: { xaxis: { renderer:$.jqplot.DateAxisRenderer, tickInterval: '1 day', tickOptions:{formatString:'%y/%m/%d'} } } }); });</script> 
+6
source share
1 answer

You can use the dataRendererOptions parameter to declare possible files, for example:

 plo12 = $.jqplot('chart2', jsonurl,{ title: 'AJAX JSON Data Renderer', dataRenderer: ajaxDataRenderer, dataRendererOptions: {file1:'name_of_file_1', file2:'name_of_file2'} axes: { xaxis: { 

The following use of for-each to iterate through dataRendererOptions - Object:

 var ajaxDataRenderer = function(url, plot,op) { var ret = null; $.each(op,function(i,n) { $.ajax({ // have to use synchronous here, else returns before data is fetched async: false, url: url+'/'+i, dataType:'json', success: function(data) { ret[]= data; } }); //end ajax });//end each return ret; } 

This code is not test, but the idea may suit your needs.

+2
source

Source: https://habr.com/ru/post/892416/


All Articles