Home forums Using CanvasJS Need help with JSON

This topic contains 2 replies, has 1 voice, and was last updated by  Nightflyer 1 year, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8404

    Nightflyer
    Participant

    http://www.fyrobe-club-sisseln.ch/labor2/parse_text_files_retentions.php

    The JSON above shall be convertet into a CanvasJS graph, i already tried the following:

    
    $.getJSON( 'parse_text_files_retentions.php', function( data ){
    
    			var chart = new CanvasJS.Chart("chartContainer", {
    				title :{
          					text: "Retention"
          				},
          				axisX: {						
          					title: "Retention time"
          				},
          				axisY: {						
          					title: "Peak signal"
          				},
    				zoomEnabled: true,
          				panEnabled: true,
                                    data: data
              		});
                            chart.render();
            });
    

    and

    
    $.getJSON( 'parse_text_files_retentions.php', function( data ){
    
    			var chart = new CanvasJS.Chart("chartContainer", {
    				title :{
          					text: "Retention"
          				},
          				axisX: {						
          					title: "Retention time"
          				},
          				axisY: {						
          					title: "Peak signal"
          				},
    				zoomEnabled: true,
          				panEnabled: true
              		});
    
    			for( x=0, y=data.length; x<y; x++ ){
    
    				//Iterate Files
    				chart.options.data[y].type = 'column';
    
    				for( i=0, j=data[y].dataPoints.length; i<j; i++ ){				
    
    					chart.options.data[y].dataPoints.push( { x : data[y].dataPoints[i].x, y : data[y].dataPoints[i].y });
    
    				}
    				
    
    			}
     
              		chart.render();
    			
    
    		});
    

    Both doesn’t work (obviously). I get a blank graph with only the correct axes and title. Where am I wrong with including the data points?

    Thank you very much in advance

    • This topic was modified 1 year, 9 months ago by  Nightflyer.
    #8406

    Nightflyer
    Participant

    problem solved, the values in the JSON were quotet with “”. Parsing the values with (float) helped 🙂

    #8411

    Nightflyer
    Participant

    How can I add a click-function to a graph after the graph is created?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.