HighCharts工具提示问题

时间:2014-05-10 07:29:42

标签: highcharts

我使用常用​​功能使用highchart生成线图。对于某些图表类型我想要工具提示没有任何点格式,而另一个想要使用格式化程序功能如何实现这一点。从下面的代码图表类型1工具提示diappear。

  

工具提示:{                       valueSuffix:'',                       pointFormat :( chartType == 1?' {series.name}:    {point.y}
' :'' ),                       shared:(chartType == 1?true:false),

                formatter: function() {
                    if (chartType == 2) {
                        return '' + this.point.tooltip + ': ' + (chartType == 2 ? this.y.toFixed(1) : this.y.toFixed(0));
                    } 
                    else {
                        return false;
                    }
                }

1 个答案:

答案 0 :(得分:1)

如果要禁用选项,请使用null值,而不是空字符串('')。请参阅:http://jsfiddle.net/Yrygy/133/

但是我认为最好添加一个if-else语句,而不是另外三个,请参阅:http://jsfiddle.net/Yrygy/134/

    var chartType = 1,
        tooltip = {
            valueSuffix: ''
        };

    if (chartType == 1) {
        tooltip.pointFormat = '{series.name}: {point.y}';
        tooltip.shared = true;
    } else {
        tooltip.shared = false;
        tooltip.formatter = function () {
            if (chartType == 2) {
                return '' + this.point.tooltip + ': ' + (chartType == 2 ? this.y.toFixed(1) : this.y.toFixed(0));
            } else {
                return false;
            }
        }
    }

然后创建图表:

    chart = new Highcharts.Chart({
        tooltip: tooltip,
        // other options
    });
相关问题