JavaScript Multi Series Charts are useful when comparing multiple series of data. You can add more than one data series element to data Array in order to create Multi Series Chart. It is supported by all charts in CanvasJS Library except pie, doughnut, funnel & pyramid chart. Given example shows the temperature variation among different beaches using a multi series chart. It also includes source code that you can edit in-browser or save to run the chart locally.
window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { animationEnabled: true, title:{ text: "Daily High Temperature at Different Beaches" }, axisX: { valueFormatString: "DD MMM, YY" }, axisY: { title: "Temperature (in °C)", suffix: " °C" }, legend:{ cursor: "pointer", fontSize: 16, itemclick: toggleDataSeries }, toolTip:{ shared: true }, data: [{ name: "Myrtle Beach", type: "spline", yValueFormatString: "#0.## °C", showInLegend: true, dataPoints: [ { x: new Date(2017,6,24), y: 31 }, { x: new Date(2017,6,25), y: 31 }, { x: new Date(2017,6,26), y: 29 }, { x: new Date(2017,6,27), y: 29 }, { x: new Date(2017,6,28), y: 31 }, { x: new Date(2017,6,29), y: 30 }, { x: new Date(2017,6,30), y: 29 } ] }, { name: "Martha Vineyard", type: "spline", yValueFormatString: "#0.## °C", showInLegend: true, dataPoints: [ { x: new Date(2017,6,24), y: 20 }, { x: new Date(2017,6,25), y: 20 }, { x: new Date(2017,6,26), y: 25 }, { x: new Date(2017,6,27), y: 25 }, { x: new Date(2017,6,28), y: 25 }, { x: new Date(2017,6,29), y: 25 }, { x: new Date(2017,6,30), y: 25 } ] }, { name: "Nantucket", type: "spline", yValueFormatString: "#0.## °C", showInLegend: true, dataPoints: [ { x: new Date(2017,6,24), y: 22 }, { x: new Date(2017,6,25), y: 19 }, { x: new Date(2017,6,26), y: 23 }, { x: new Date(2017,6,27), y: 24 }, { x: new Date(2017,6,28), y: 24 }, { x: new Date(2017,6,29), y: 23 }, { x: new Date(2017,6,30), y: 23 } ] }] }); chart.render(); function toggleDataSeries(e){ if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) { e.dataSeries.visible = false; } else{ e.dataSeries.visible = true; } chart.render(); } }
You can easily change the type of chart using type property available at data series level. Some other customizations include shared(Tool Tip), showInLegend, legendMarkerType, etc.