WhoAmI
Posts: 33
Joined: Tue Dec 01, 2015 1:22 pm

Highcharts should not draw graph if the value is 0

Hello,

I am using Highcharts and it reports for the whole year.

I have data only until August (as it is August) but when I plot the graph it plots until December with value as 0 (Sep to Dec).

I don´t want to plot the graph if the values are 0 and I want to plot only until August for this year but for the last year it has to plot until Dec as I have data in my database.

Here's my code:

Code: Select all

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script>
Highcharts.chart('container', {

    xAxis: {
		min: 0,
		max: 11,
      categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
		crosshair: true
    },

    yAxis: {
      min: 0,
		title: {
            text: '',
        }
    },
	
	plotOptions: {
        series: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: true
        }
    },
	
	exporting: {
    sourceWidth: 1800,
    sourceHeight: 500,
    scale: 1 
},
	credits: {
      enabled: false
  },
    chart: {
        type: 'line'
    },
    title: {
        text: "Demo Graph"
    },
    subtitle: {
        text: 'Marks'
    },
    tooltip: {
        shared: true
    },
    series: [{
        name: 'Average',
        //type: 'column',
		color: 'orange',
        
data: [
[0, <?php echo round($janCount);?>], 
[1, <?php echo round($febCount);?>],
[2, <?php echo round($marCount);?>], 
[3, <?php echo round($aprCount);?>],
[4, <?php echo round($mayCount);?>],
[5, <?php echo round($junCount);?>],
[6, <?php echo round($julCount);?>], 
[7, <?php echo round($augCount);?>],
[8, <?php echo round($sepCount);?>],
[9, <?php echo round($octCount);?>], 
[10, <?php echo round($novCount);?>],
[11, <?php echo round($decCount);?>]],

        marker: {
            enabled: true
        },
        states: {
            hover: {
                lineWidth: 0
            }
        },
        enableMouseTracking: true
    }, {
        name: 'Minimum',
        //type: 'spline',
		color: 'darkblue',
        
data: [
<?php echo round($janCount1);?>,
<?php echo round($febCount1);?>,
<?php echo round($marCount1);?>,
<?php echo round($aprCount1);?>, 
<?php echo round($mayCount1);?>,
<?php echo round($junCount1);?>, 
<?php echo round($julCount1);?>, 
<?php echo round($augCount1);?>, 
<?php echo round($sepCount1);?>, 
<?php echo round($octCount1);?>, 
<?php echo round($novCount1);?>,
<?php echo round($decCount1);?>],

        marker: {
        	 enabled: true
        },
        states: {
            hover: {
                lineWidth: 0
            }
        },
        enableMouseTracking: true
    }]
});
</script>	
Any help on this
wojtek
Posts: 433
Joined: Tue Jul 03, 2018 12:32 pm

Re: Highcharts should not draw graph if the value is 0

Hi WhoAmI,

Could you please send me simplified online demo of your chart (for e.g jsfiddle) or code that have valid data? Then I will be able to reproduce your issue easily and help you better. Code you sent me above have data from php so I can't reproduce it.

Best regards.
Wojciech Chmiel
Highcharts Developer
WhoAmI
Posts: 33
Joined: Tue Dec 01, 2015 1:22 pm

Re: Highcharts should not draw graph if the value is 0

Hello Wotjek,

can you just have a look into my below code.

Code: Select all

<script>
Highcharts.chart('container', {
    xAxis: {
		min: 0,
		max: 11,
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
		crosshair: true
    },
    yAxis: {
        min: 0,
		title: {
            text: '',
        }
    },
	
	plotOptions: {
        series: {
            dataLabels: {
                enabled: true
            },
            enableMouseTracking: true
        }
    },
	
	
    chart: {
        type: 'line'
    },
 
    tooltip: {
        shared: true
    },
    series: [{
        name: 'Test',
        //type: 'column',
		color: 'orange',
        data: [[0,96], [1, 96],[2, 97], [3, 0],[4, 99], [5, 84],[6, 98], [7, 99], [8, 100],[9, 0], [10, 0],[11, 0]],
        marker: {
            enabled: true
        },
        states: {
            hover: {
                lineWidth: 0
            }
        },
        enableMouseTracking: true
    }, {
        name: 'Test Case',
        //type: 'spline',
		color: 'darkblue',
        data: [90,89,93,100, 97,54, 89, 97, 100, 0, 0,0],
        marker: {
        	 enabled: true
        },
        states: {
            hover: {
                lineWidth: 0
            }
        },
        enableMouseTracking: true
    }]
});
</script>	


I don't want to draw the line if it is 0.

Ex: For March, I have 0 and in that case it has to draw graph from Jan to Feb and again it starts from April to December (Incase in the middle if it doesn't have any 0's).

Could you please help me out
wojtek
Posts: 433
Joined: Tue Jul 03, 2018 12:32 pm

Re: Highcharts should not draw graph if the value is 0

Hi WhoAmI,

Use null instead of 0 value in that points. Check the demo posted below.

Demo:
https://jsfiddle.net/BlackLabel/Lsk7c9zp/1/

Kind regards.
Wojciech Chmiel
Highcharts Developer
WhoAmI
Posts: 33
Joined: Tue Dec 01, 2015 1:22 pm

Re: Highcharts should not draw graph if the value is 0

Dear wotjek,

Thanks for the link and am unable to access it now but I got the idea and so I implemented it.

Here's the error which I got.

Code: Select all


1st set of data

data: [[0,96], [1, 96], [2, 97], [3, 100],[4, 99], [5, 84], [6, 98], [7, 99], [8, 100], [9, ], [10, ], [11, ]],

2nd set of data

 data: [[0, 90], [1, 89], [2, 93], [3, 100], [4, 97], [5, 54], [6, 89], [7, 97], [8, 100], [9, ], [10, ],[11, ]],

Result: In the 1st set data as 9, 10 and 11 are empty the Highcharts are placing the value of 9, 10 and 11 in 0, 1 and 2 categories repectively.

Same with the 2nd set of data as well.

Screenshot result is attched. Hope you will have an idea now.
Attachments
Highchart Result
Highchart Result
Highchart.JPG (37.43 KiB) Viewed 7459 times
wojtek
Posts: 433
Joined: Tue Jul 03, 2018 12:32 pm

Re: Highcharts should not draw graph if the value is 0

WhoAmI,

I meant js null primitive value - https://developer.mozilla.org/en-US/doc ... jects/null

Try it:

Code: Select all

1st set of data

data: [[0,96], [1, 96], [2, 97], [3, 100],[4, 99], [5, 84], [6, 98], [7, 99], [8, 100], [9, null], [10, null], [11, null]],

2nd set of data

 data: [[0, 90], [1, 89], [2, 93], [3, 100], [4, 97], [5, 54], [6, 89], [7, 97], [8, 100], [9, null], [10, null],[11, null]],
Kind regards.
Wojciech Chmiel
Highcharts Developer
ed1nh0
Posts: 4
Joined: Tue Jul 27, 2021 5:13 pm
Location: Brazil
Contact: Website

Re: Highcharts should not draw graph if the value is 0

@wojtek is it possible to output null on the chart and 0 when exporting to CSV/XLS files?
I'm using the HC's export-data module to do so, but getting blank cells instead of zeros.
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Highcharts should not draw graph if the value is 0

Hi ed1nh0,

I will answer your question at another topic that you created.
viewtopic.php?f=9&t=47076

Regards.
Sebastian Hajdus
Highcharts Developer

Return to “Highcharts Usage”