Home forums Using CanvasJS Use two datasets in one Line Graph

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by  sss04 4 months, 2 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #11538

    sss04
    Member

    Hi!

    I’m new to CanvasJS, and I’m trying to create a line plot with multiple lines. My current code doesn’t work, any recommendations?

    var version=3;
    console.log(version);
    
    var utm = "+proj=utm +zone=17";
    var wgs84 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
    var fulldata=[];
    var abby = [];
    var kyle = [];
    var dataSeries = { type: "line" };
    var abby = function() {
    	var dataPoints = [];
    	d3.csv('Abby.csv',function(results){
    		results.forEach(function(d){d.time=parseFloat(d.Day)+(parseFloat(d.Hour)/24)+((parseFloat(d.Minute)/60)/24);});
    		results.forEach(function (d){dataPoints.push({
    		      x: d.time,
    		      y: parseFloat(d.Height)                
    		    });
    		});
    		var data=[];
    		dataSeries.dataPoints = dataPoints;
    		data.push(dataSeries); 
    		abby=data;
    		console.log(data);
    		});	
    };
    var kyle = function() {
    	var dataPoints = [];
    	d3.csv('Kyle.csv',function(results){
    		results.forEach(function(d){d.time=parseFloat(d.Day)+(parseFloat(d.Hour)/24)+((parseFloat(d.Minute)/60)/24);});
    		results.forEach(function (d){dataPoints.push({
    		      x: d.time,
    		      y: parseFloat(d.Height)                
    		    });
    		});
    		var data=[];
    		dataSeries.dataPoints = dataPoints;
    		data.push(dataSeries);  
    		kyle=data;
    
    		});	
    };
    abby(); 
    console.log(fulldata);
    window.onload = function () {
    	 var chart = new CanvasJS.Chart("chartContainer",
    			    {
    			      zoomEnabled: true,
    			      title:{
    			        text: "Heights!"
    			      },
    			      animationEnabled: true,
    			      axisX:{
    			    	title: "Time",
    			        labelAngle: 30
    			      },
    			      
    			      axisY :{
    			    	title: "Height (m)",  
    			        includeZero:true
    			      },
    			      
    			      data: [abby,kyle]
    			      
    			    });
    
    chart.render();
    };
    #11539

    sss04
    Member

    Forgot to call kyle(); , but even when I do, it doesn’t work.

    #11545

    Sanjoy
    Moderator

    Hi,

    Can you please provide a sample JSON to help you out.

    #11580

    sss04
    Member

    Abby.csv
    Kyle.csv

    Just some random data.

    #11581

    sss04
    Member

    Nevermind, Solved it!

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

You must be logged in to reply to this topic.