user1286856
user1286856

Reputation: 75

Use a variable for Highcharts yAxis.Max

Im trying to pass a variable('maxValue') into my Highcharts guage . I cant get the variable to pass in successfully, the graph renders but without the value.

Ive tried Number and parseInt Functions but neither make a difference.

I setup a JS fiddle here: http://jsfiddle.net/d5d4cgbe/16/

The code section in question:

var maxValue = 120; //set the maxValue var

 $('#visitPerformanceWeek').highcharts(Highcharts.merge(gaugeOptions, {
            yAxis: {
                min: 0,
                max: maxValue,
                title: {
                    text: 'Hours Worked'
                }
            },

I will eventually be passing a value collected from an AJAX request, this part I have working but have excluded from the fiddle to keep it simple. Help appreciated

Upvotes: 1

Views: 755

Answers (2)

chridam
chridam

Reputation: 103365

For setting the maxValue dynamically, something like setExtremes should do it. Try

chart.yAxis[0].setExtremes(0,maxValue);

Another alternative is the update method:

chart.yAxis[0].update({ max: maxValue });

For the maxValue to be displayed by the solidgauge, you need to specify a tickerInterval which divides into the maxValue. Presently, the chart is generating a default tick interval e.g. 10, which adds up to 100. For example, a maxValue of 120, you may set the tickInterval to 12

   yAxis: {
        min: 0,
        max: 120,
        tickInterval: 12,
        ...
   }

JSFiddle

Upvotes: 2

Dipali Vasani
Dipali Vasani

Reputation: 2536

Check here : http://jsfiddle.net/d5d4cgbe/23/

you can set value using following command :

chart.yAxis.max = maxValue;

check browser console for yAxis value.

Upvotes: 0

Related Questions