Search code examples
javascriptasp.netvisual-studiocanvasjs

CanvasJS value is 0 not showing in chart


I'm using CanvasJs for the first time for my charts but I noticed that everytime a value is zero the graph doesn't display this. I'm using a chart which combines a line chart and a bar chart so this is important to show if there has been zero change between the two values. The piece of code for the line graph is as follows:

{
                type: "line",
                name: "Cumulatief",
                showInLegend: true,
                yValueFormatString: "€#",
                dataPoints: [
                    { x: new Date(dateValue1) , y: 0 }
                    ] 
}

I hope that someone can help me so that I can display the value zero on the line chart.


Solution

  • Y-value 0 is being rendered irrespective of chart-type is line or column and seems to be working fine.

    However value 0 is not being displayed in toolTip as you are setting yValueFormatString to '€#'. Changing it to '€0' will work fine in this case. Check the working code below:

    var chart = new CanvasJS.Chart("chartContainer", {
        data: [{
            type: "line",
            name: "Cumulatief",
            showInLegend: true,
            yValueFormatString: "€0",
            dataPoints: [
              	{ x: new Date(2018,03,19) , y: 0 }
            ] 
        }]
    });
    
    chart.render();
    <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
    <div id="chartContainer" style="height: 260px; width: 100%;"></div>