简体   繁体   中英

update the yAxis min value and tooltip dynamically in highcharts

I am unable to update the chart's yaxis min tick to 0 dynamically. I tried to built a generic chart for all the types of charts i am working on. some of the charts have negative values so i need negative axis and column chart with percentages, don't have negative axis. I'm setting a parameter in the javascript code to see if its a percent or not, then show the min tick for y-axis according to it. Also the tooltip has to be dynamic, which i am not able to achieve. I am missing something in my current approcach This is the fiddle

$(function () {
    var isPercent = 'true';
    $('#container').highcharts({
        chart: {
            type: 'column'
        },

        series: [{
            name: '1',
            data: [10, 31, 100, 89, 92, 12]
        }, {
            name: '2',
            data: [90, 69, 0, 11, 8, 88]
        }, {
            name: '3',
            data: [90, 69, 0, -11, 8, 88],
            type: 'line'
        }]
    },function(chart){
        if(isPercent === 'true') {
                chart.options.yAxis['min'] = 0;
                console.log(chart.options.yAxis['min']);
            }


    });
});
$(function () {
    var isPercent = 'true';
        $('#container').highcharts({
            chart: {
                type: 'column'
            },
            yAxis:{
                min : (isPercent === 'true' ? 0 : null),
                labels:{
                    format:(isPercent === 'true' ? '{value}%' : '{value}'),
                }
            },
            tooltip:{
                pointFormat:'<span style="color:{series.color}">{series.name}</span>: <b>{point.y:,.0f}' + (isPercent === 'true' ? '%' : '') + '</b><br/>'
            },
            series: [{
                name: '1',
                data: [10, 31, 100, 89, 92, 12]
            }, {
                name: '2',
                data: [90, 69, 0, 11, 8, 88]
            }, {
                name: '3',
                data: [90, 69, 0, -11, 8, 88],
                type: 'line'
            }]
        });
    });

This is for the min. updated: http://jsfiddle.net/CaPG9/31/

Like this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM