Showing Blank chart with Axis when there are no dataPoints- CanvasJS
Showing Blank chart with Axis when there are no dataPoints- CanvasJS
HTML
<script src="http://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 chart = new CanvasJS.Chart("chartContainer",
{ title:{
text: "Moving Title Around",
verticalAlign: "top", // "top", "center", "bottom"
horizontalAlign: "center" // "left", "right", "center"
},
data: [
{
type: "doughnut",
dataPoints: [
//{x: 1, y:20}
]
}
]
});
isNoDataAvailable();
chart.render();
function isNoDataAvailable(){
var options = chart.options;
if(!options.axisY)
options.axisY = {};
for(var i = 0; i< options.data.length; i++){
if(options.data[i].dataPoints.length ===0){
options.title.horizontalAlign="center";
options.title.verticalAlign="center";
options.title.text='No result';
options.axisY.maximum = 0;
}
else{
options.axisY.maximum=null;
break;
}
}
}