【问题标题】:HighCharts : How to add or remove "chart context menu" from chart container?HighCharts:如何从图表容器中添加或删除“图表上下文菜单”?
【发布时间】:2019-04-05 23:33:12
【问题描述】:

highcharts 中是否有任何属性可用于删除图表上下文菜单(右侧看起来像汉堡菜单)出现在使用 javascript 的this 柱形图中?

默认情况下,此选项是否包含在 highchart 中?我也有一个折线图,但默认情况下没有图表上下文菜单。另外,如果我想向该折线图添加图表上下文菜单,我该怎么做?

Highcharts.chart('container', {
  chart: {
    type: 'column',
    events: {
      load: function() {
        var series = this.series[0];
        setInterval(function() {
          newValue = Math.random() * 100;
          series.update({
            data: [newValue],
          }, true)
        }, 1000);
      }
    }
  },
  title: {
    text: 'Monthly Average Rainfall'
  },
  subtitle: {
    text: 'Source: WorldClimate.com'
  },
  xAxis: {
    categories: [
      'Jan'
    ],
    crosshair: true
  },
  yAxis: {
    min: 0,
    title: {
      text: 'Rainfall (mm)'
    }
  },
  tooltip: {
    headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
    pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
      '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
    footerFormat: '</table>',
    shared: true,
    useHTML: true
  },
  plotOptions: {
    column: {
      pointPadding: 0.2,
      borderWidth: 0
    }
  },
  series: [{
    name: 'Tokyo',
    data: [49.9]

  }, {
    name: 'New York',
    data: [83.6]

  }, {
    name: 'London',
    data: [48.9]

  }, {
    name: 'Berlin',
    data: [42.4]

  }]
});

【问题讨论】:

    标签: javascript highcharts contextmenu


    【解决方案1】:

    只需包含&lt;script src="https://code.highcharts.com/modules/exporting.js"&gt;&lt;/script&gt;

    您可以通过添加buttonOptions 来启用或禁用它。默认为 true

    Highcharts.chart('container', {
        navigation: {
            buttonOptions: {
                enabled: true
            }
        }
    });
    

    Highcharts.chart('container', {
      chart: {
        type: 'column',
        events: {
          load: function() {
            var series = this.series[0];
            setInterval(function() {
              newValue = Math.random() * 100;
              series.update({
                data: [newValue],
              }, true)
            }, 1000);
          }
        }
      },
      title: {
        text: 'Monthly Average Rainfall'
      },
      subtitle: {
        text: 'Source: WorldClimate.com'
      },
      xAxis: {
        categories: [
          'Jan'
        ],
        crosshair: true
      },
      yAxis: {
        min: 0,
        title: {
          text: 'Rainfall (mm)'
        }
      },
      tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
          '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
      },
      plotOptions: {
        column: {
          pointPadding: 0.2,
          borderWidth: 0
        }
      },
      series: [{
        name: 'Tokyo',
        data: [49.9]
    
      }, {
        name: 'New York',
        data: [83.6]
    
      }, {
        name: 'London',
        data: [48.9]
    
      }, {
        name: 'Berlin',
        data: [42.4]
    
      }]
    });
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    
    <div id="container" style="height: 400px; margin-top: 1em"></div>

    【讨论】:

    • 谢谢。这帮助我禁用了柱形图中的图表上下文菜单。但是在代码中添加它并没有帮助我在样条图中添加图表上下文菜单。样条图不支持此选项还是有其他方法可以做到吗?
    • 我用导航选项更新了这个小提琴jsfiddle.net/com43tqb,它没有任何问题。我无法弄清楚我的代码出了什么问题。
    • 是的。当它被隔离时,它会。但在我的项目中没有。我的原始项目有两个图表。条形图和样条图。我还不明白为什么它在我的项目中不能这样工作。
    • 好的,我找到了问题所在。我以错误的顺序包含了脚本文件。
    • @IsharaAmarasekera 好的,很好
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多