繁体   English   中英

在高图中动态更新yAxis最小值和工具提示

[英]update the yAxis min value and tooltip dynamically in highcharts

我无法将图表的yaxis最小刻度自动更新为0。 我试图为我正在处理的所有类型的图表构建通用图表。 一些图表具有负值,所以我需要带有百分比的负轴和柱形图,而没有负轴。 我在javascript代码中设置了一个参数,看它是否是百分比,然后根据它显示y轴的最小刻度。 工具提示也必须是动态的,我无法实现。 我目前的方法中缺少某些东西这是小提琴

$(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'
            }]
        });
    });

这是分钟。 更新: http : //jsfiddle.net/CaPG9/31/

像这样?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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