0
votes

I have created Highchart form php table. Right now Y-axis max. and interval values are fixed. How can I make them dynamic using last four records. Say max. value is 20 from query then intervals will be 5. For max value I got query which returns max. value from 2 column and last 4 records. Mysql query:

 SELECT GREATEST(MAX(step1), MAX(step2)) FROM workflow1 ORDER BY id DESC LIMIT 4

Highchart script:

<script>
Highcharts.chart('container', {

    data: {
    table: 'datatable'
},
credits: {
  enabled: false
},
chart: {
    type: 'column'
},
title: {
    text: 'Results',
    style: {
        color: '#FF00FF',
        fontWeight: 'bold'
    }
},
    legend: {
    layout: 'horizontal',
    align: 'right',
    verticalAlign: 'top',
    y: 50,
    padding: 3,
    itemMarginTop: 5,
    itemMarginBottom: 5,
    itemStyle: {
        lineHeight: '14px'
    }
},

yAxis: {

    min: 0,
    max: 100,
    tickInterval: 20,
    allowDecimals: false,
    title: {
        text: 'Time in Sec.'
    }
},
tooltip: {
    formatter: function () {
        return '<b>' + this.series.name + '</b><br/>' +
            this.point.y + ' ' + this.point.name.toLowerCase();
    }
}

});

1
I'm sorry but I don't quite understand. What is stopping you setting the yAxis properties of max and tickInterval from the results of your database query? Seems to me like you have both parts of the solution already. - dougtesting.net
You are right! But I am unable to set that query in variable and put in place of 100 or 20 (max. value and interval). - Samadhan Gaikwad
Add complete code . How you are creating values in php and bringing these values in javascript code.I am sure its easy. But add code which will help us to give solution. If still not getting, then starting point will be working-with-data docs. - Deep 3015
Do you even need to set fixed intervals? If you don't define values for min, max, or tickInterval, Highcharts will automatically generate a chart based on the current data available. - Mike Zavarello
@SamadhanGaikwad Oh, great! I've written a formal answer per your request. So glad this helped your situation. - Mike Zavarello

1 Answers

1
votes

If you don't define specific values for min, max, or tickInterval, Highcharts will automatically adjust the axis' maximum value and tick intervals based on the current data available.

The dynamic update Highcharts demo shows how this works (though you may have to wait a bit before it goes above 1 in the example): https://www.highcharts.com/demo/dynamic-update

Glad this was helpful for you!