【问题标题】:HighCharts tooltip issueHighCharts 工具提示问题
【发布时间】:2014-05-10 07:29:42
【问题描述】:

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

工具提示:{ 值后缀:'', pointFormat: (chartType == 1 ? '{series.name}: {point.y}
' : '' ) , 共享:(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;
                    }
                }

【问题讨论】:

    标签: highcharts


    【解决方案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
        });
    

    【讨论】:

      猜你喜欢
      • 2022-07-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2014-03-04
      • 2023-01-26
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多