Basic Column Chart - CanvasJS
Basic Column Chart
by JohnCarranza
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
title: {
text: "House Median Price"
},
axisY2: {
title: "Median List Price",
prefix: "$",
suffix: "K"
},
toolTip: {
shared: false
},
legend: {
cursor: "pointer",
verticalAlign: "top",
horizontalAlign: "center",
dockInsidePlotArea: true,
itemclick: toogleDataSeries
},
data: [{
type:"line",
axisYType: "secondary",
name: "San Fransisco",
showInLegend: true,
markerSize: 0,
yValueFormatString: "$#,###k",
dataPoints: [
{ x: 0.8, y: 850 },
{ x: 2.1, y: 889 },
{ x: 3, y: 890 }
]
},
{
type: "line",
axisYType: "secondary",
name: "Manhattan",
showInLegend: true,
markerSize: 0,
yValueFormatString: "$#,###k",
dataPoints: [
{ x: 1, y: 1200 },
{ x: 2.6, y: 1200 },
{ x: 3.5, y: 1190 }
]
},
{
type: "line",
axisYType: "secondary",
name: "other",
showInLegend: true,
markerSize: 0,
yValueFormatString: "$#,###k",
dataPoints: [
{ x: 1, y: 1210 }
]
},
{
type: "line",
axisYType: "secondary",
name: "other2",
showInLegend: true,
markerSize: 0,
yValueFormatString: "$#,###k",
dataPoints: [
{ x: 1, y: 900 },
{ x: 2, y: 900 }
]
},
{
type: "line",
axisYType: "secondary",
name: "Seatle",
showInLegend: true,
markerSize: 0,
yValueFormatString: "$#,###k",
dataPoints: [
{ x: 1, y: 1200 },
{ x: 2.4, y: 415 },
{ x: 4.5, y: 419 },
]
},
{
type: "line",
axisYType: "secondary",
name: "Los Angeles",
showInLegend: true,
markerSize: 0,
yValueFormatString: "$#,###k",
dataPoints: [
{ x: 1.5, y: 529 },
{ x: 2.9, y: 540 },
{ x: 3.1, y: 539 },
]
}]
});
chart.render();
function toogleDataSeries(e){
if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else{
e.dataSeries.visible = true;
}
chart.render();
}
}