HighCharts - Show tooltip on column where value is 0 or null

北战南征 提交于 2019-12-13 16:51:20

问题


I had implemented the HighCharts in the framework in my company, and I can say that we are super satisfied with it. But we have a problem, we don't know how to solve.

In column graphs, when a column has its value equal to zero, it is no visual information about it, the column is just omitted. I want it displayed in a tooltip when the user mouses over the space of the column where the value is equal to 0.

Watch the fiddle below where it generates a bar chart with several columns with value 0, or worthless.

JsFiddle

The method where the chart runs:

GraficoBarra(arrayPropriedades, arrayDados, arrayDrillDown);

回答1:


As @wergeld said, you need to pass 0-based values to options, otherwise you won't get displayed nothing at all. For nulls it's no possible, since this doesn't have value.

Now,you need to set minPointLength, to some value (like 10), then even 0-values will be displayed as small bars. See demo: http://jsfiddle.net/EJK4e/12/

Just to be on the same page - to display tooltip, you need point graphic, otherwise there will be no hover event for triggering tooltip to show up.




回答2:


Why not make it a shared tooltip like this:

tooltip: {
    formatter: function() {
        var s = '<b>'+ this.x +'</b>';

        $.each(this.points, function(i, point) {
            s += '<br/>'+ point.series.name +': '+
                point.y +'m';
        });

        return s;
    },
    shared: true
},

Demo here. Note that I have added a 0 point value. If there is no point there then there is nothing to show, right?

{
    name: "2012",
    data: [
        [0, 69347.35],
        [1, 120753.55],
        [2, 0],
        [12, 95050.45]
    ]
}


来源:https://stackoverflow.com/questions/22995354/highcharts-show-tooltip-on-column-where-value-is-0-or-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!