繁体   English   中英

Highcharts'bindAxis'仅适用于一张图表

[英]Highcharts 'bindAxis' for one chart only

我正在尝试将MariMekko /市场类型的图表集成到我的应用程序中。 我在这里找到了一个有趣的实现:

http://jsfiddle.net/h2np93k1/39/

此代码构造一个树形图并向其中添加轴。 这是通过以下代码段完成的:

Highcharts.seriesTypes.treemap.prototype.bindAxes = function() {
    Highcharts.Series.prototype.bindAxes.call(this);
};

但是,如果我理解正确,这将导致我所有的treemap图都具有轴。 我不想要这个,我只想保留我的marimekko地图的轴。

谁是实现这一目标的最佳方法? 例如,是否有简单的方法来扩展图表类型?

最简单的方法是包装一个核心函数并添加条件语句,该条件语句检查选项并在需要时应用修改。

在这种情况下,我在系列中添加了isMariMekko标志。 如果为true,则执行修改后的代码。 原始函数启动是错误的:

  Highcharts.wrap(Highcharts.seriesTypes.treemap.prototype, 'bindAxes', function(proceed) {
    if (this.options.isMariMekko) {
      var treeAxis = {
        min: 0,
        dataMin: 0,
        max: 100,
        dataMax: 0
      };

      Highcharts.Series.prototype.bindAxes.call(this);
      Highcharts.extend(this.yAxis.options, treeAxis);
      Highcharts.extend(this.xAxis.options, treeAxis);

    } else {
      proceed.apply(this); // default action
    }

  });

有关包装的文档参考: https : //www.highcharts.com/docs/extending-highcharts/extending-highcharts

暂无
暂无

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

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