Area chart with color above zero - CanvasJS JavaScript Charts
Area chart with color above zero - CanvasJS JavaScript Charts
by canvasjs
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
var dataPoints = [
{ x: 10, y: 71},
{ x: 20, y: 55},
{ x: 30, y: 70 },
{ x: 40, y: 55 },
{ x: 50, y: 85 },
{ x: 60, y: 68 },
{ x: 70, y: -28 },
{ x: 80, y: 34 },
{ x: 90, y: 24 }
];
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Area chart with color above a threshold"
},
axisY:{
gridThickness:0,
stripLines:[{
value: 0,
color: "#BBBBBB",
thickness: 2,
showOnTop: true,
}]
},
data: [
{
type: "area",
dataPoints: dataPoints
},
{
type: "area",
toolTipContent: null,
highlightEnabled: false,
color: "white",
fillOpacity: 1,
markerSize: 0,
dataPoints: [
{ x: 10, y: 0},
{ x: 90, y: 0}
]
},{
type: "line",
dataPoints: dataPoints
}
]
});
chart.render();
var minimum = chart.axisY[0].get("minimum");
chart.data[1].dataPoints[0].y = minimum;
chart.data[1].dataPoints[1].y = minimum;
chart.render();