How do I put a 1-31 day for statement on PHP Highcharts graph?

Asked 2 years ago, Updated 2 years ago, 42 views

It looks like this.

Highcharts.chart('container', {
            chart: {
                type: 'column'
            },
            title: {
                text:picker+'Statistics by Media Graph'
            },
            xAxis: {
                categories: [1st, 2nd, 3rd, 4th, 5th, 7th, 8th, 9th, 10th, 12th, 13th, 14th, 15th, 16th, 18th, 18th, 21st, 21st, 22nd, 23rd, 24th, 24th, 21st, 22nd, 21st, 21st, 21st, 24th, 10th, 10th, 10th, 10th, 11th, 12th, 12th, 12th, 12th, 12th, 12th, 14th, 14th, 15th, 14th, 15th, 15th, 12th, 12th, 12th, 12**
            },
            yAxis: {
                min: 0,
                title: {
                    text: ''
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                    }
                }
            },
            legend: {
                align: 'right',
                x: -30,
                verticalAlign: 'top',
                y: 25,
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
                borderColor: '#CCC',
                borderWidth: 1,
                shadow: false
            },
            tooltip: {
                headerFormat: '<b>{point.x}</b><br/>',
                pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
            },
            plotOptions: {
                column: {
                    stacking: 'normal',
                    dataLabels: {
                        enabled: true,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
                    }
                }
            },
            series: [{
                name: 'test',
                data: [parseInt($("#a0").text()), parseInt($("#a1").text()), parseInt($("#a2").text()), parseInt($("#a3").text()), parseInt($("#a4").text()), parseInt($("#a5").text()), parseInt($("#a6").text())]
            }, {
                name: 'test1',
                data: [2, 2, 3, 2, 1]
            }, {
                name: 'test2',
                data: [3, 4, 4, 2, 5]
            }, {
                name: 'test3',
                data: [3, 4, 4, 2, 5]
            }, {
                name: 'test4',
                data: [3, 4, 4, 2, 5]
            }, {
                name: 'test5',
                data: [3, 4, 4, 2, 5]
            }, {
                name: 'test6',
                data: [3, 4, 4, 2, 5]
            }, {
                type: 'spline',
                name: 'test7',
                data: [4, 32, 12, 35, 66]
            }, {
                type: 'test8',
                name: 'Total',
                data: [3, 4, 4, 2, 5]
            }]
        });
    });

Above categories: [1st, 2nd, 3rd, 4th, 5th, 7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th, 15th, 16th, 17th, 18th, 21st, 21st, 21st, 22nd, 23rd, 23rd, 24th, 24th, 12th, 11th, 12th, 12th, 13th, 14th, 14th, 14th, 15th, 19th, 21st, 21st, 21st, 21st, 21st, 21st, 21st, 21st, 21st, 21st, 21st, 21st, 23rd, I want to put it in the for moon for 1-31 days, but I can't put it in no matter how much I try. Tell me how to do it!

javascript jquery

2022-09-22 20:08

1 Answers

You can call the loop statements that add data after defining them externally.

var getDay = function() {
                  var data = [];
                  for (var i = 0; i< 31; i++) {
                    data.push(i+'day');
                  }
                  return data;
               }

Highcharts.chart('container', {
            chart: {
                type: 'column'
            },
            title: {
                text:picker+'Statistics by Media Graph'
            },
           categories: getDay()
            },
            yAxis: {
                min: 0,
                title: {
                    text: ''
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                    }
                }
            },


2022-09-22 20:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.