php - Rickshaw : data for multiple series not working -
i'm trying create charts using rickshaw, importing data ajax generated in php.
if use static datas, chart displays; if copy/paste data generated in php (from console/log()), chart displays; if try put datas variable, , use var in js, doesnt' work. :(
this console log of .php : (as said, if copy paste block of code .js substituting "dataoutevo" var, graph displays should. so, don't think data problem.
[ { name: "ligne", data: [{x:0,y:35},{x:1,y:34},{x:2,y:36},{x:3,y:35},{x:4,y:40},{x:5,y:35},{x:6,y:37},{x:7,y:40},{x:8,y:45},{x:9,y:46},{x:10,y:55},{x:11,y:63},{x:12,y:61},{x:13,y:45},{x:14,y:48},{x:15,y:49},{x:16,y:45},{x:17,y:44},{x:18,y:52},{x:19,y:43},{x:20,y:37},{x:21,y:36},{x:22,y:37},{x:23,y:34}], color: palette.color() }, { name: "ligne", data: [{x:0,y:10},{x:1,y:15},{x:2,y:13},{x:3,y:15},{x:4,y:14},{x:5,y:16},{x:6,y:17},{x:7,y:25},{x:8,y:23},{x:9,y:24},{x:10,y:25},{x:11,y:28},{x:12,y:27},{x:13,y:21},{x:14,y:23},{x:15,y:19},{x:16,y:18},{x:17,y:16},{x:18,y:15},{x:19,y:14},{x:20,y:15},{x:21,y:16},{x:22,y:15},{x:23,y:16}], color: palette.color() }, { name: "ligne", data: [{x:0,y:45},{x:1,y:49},{x:2,y:49},{x:3,y:50},{x:4,y:54},{x:5,y:51},{x:6,y:54},{x:7,y:65},{x:8,y:68},{x:9,y:70},{x:10,y:80},{x:11,y:91},{x:12,y:88},{x:13,y:66},{x:14,y:71},{x:15,y:68},{x:16,y:63},{x:17,y:60},{x:18,y:67},{x:19,y:57},{x:20,y:52},{x:21,y:52},{x:22,y:52},{x:23,y:50}], color: palette.color() }, { name: "ligne", data: [{x:0,y:10},{x:1,y:15},{x:2,y:12},{x:3,y:5},{x:4,y:9},{x:5,y:15},{x:6,y:45},{x:7,y:125},{x:8,y:345},{x:9,y:256},{x:10,y:312},{x:11,y:345},{x:12,y:299},{x:13,y:165},{x:14,y:354},{x:15,y:368},{x:16,y:254},{x:17,y:213},{x:18,y:312},{x:19,y:165},{x:20,y:54},{x:21,y:32},{x:22,y:10},{x:23,y:5}], color: palette.color() }, { name: "ligne", data: [{x:0,y:2},{x:1,y:3},{x:2,y:2},{x:3,y:1},{x:4,y:1},{x:5,y:2},{x:6,y:3},{x:7,y:15},{x:8,y:45},{x:9,y:27},{x:10,y:40},{x:11,y:42},{x:12,y:35},{x:13,y:18},{x:14,y:42},{x:15,y:40},{x:16,y:30},{x:17,y:25},{x:18,y:40},{x:19,y:20},{x:20,y:6},{x:21,y:4},{x:22,y:2},{x:23,y:1}], color: palette.color() } ]
and js goes wrong :
$(document).ready(function(){ $.ajax({ url: 'dataoutevo.php', //le fichier qui va nous fournir la réponse success: function(data) { var dataoutevo = data; console.log(dataoutevo); var palette = new rickshaw.color.palette( { scheme: 'spectrum2001' } ); var graph = new rickshaw.graph({ element: document.queryselector("#chart"), width: 960, height: 260, renderer: 'line', series: dataoutevo }); graph.render(); } }); });
could tell me goes wrong ? thank :) mathieu
i'm asking myself if shouldn't go way, using this:
$fp = fopen('dataoutevo.json', 'w'); fwrite($fp, json_encode($js)); fclose($fp);
and :
var palette = new rickshaw.color.palette(); new rickshaw.graph.ajax( { element: document.getelementbyid("chart"), width: 800, height: 500, renderer: 'line', dataurl: 'dataoutevo.json', ondata: function(d) { rickshaw.series.zerofill(d); return d; }, oncomplete: function(transport) { var graph = transport.graph; var detail = new rickshaw.graph.hoverdetail({ graph: graph }); } } );
but it's still not working … can me , tell me i'm doing wrong ?
using first implementation should work fine. think problem when call:
success: function(data) {
the data variable returned php string (you can check using javascript function) -
console.log(typeof(data));
on php code should returning (associative) array , make sure you're using json_encode() function -
echo json_encode($output);
and on js side cast returned data using json.parse method -
var json_data = json.parse(data);
hope helps!
Comments
Post a Comment