在绘制之前设置(自定义)按钮的初始状态-HighCharts

时间:2018-07-11 09:44:25

标签: javascript highcharts states

在HighCharts中,有什么方法可以在绘制图表之前定义按钮的初始/默认状态?

现在我在绘制图表之后执行一个功能,并禁用一些自定义按钮(范围按钮)

chart.exportSVGElements[X].setState(3)

但是我想知道是否不可能简单地定义一些东西

states: {
  hover: {
    lineWidth: 2
  }
},
currentState: 3

在我的“配置”对象中。

在此先感谢您,如果我在文档中错过了,敬请谅解

编辑: 是的,对不起,您是对的,我没有显示如何初始化按钮:

exporting: {
sourceWidth: 1400,
sourceHeight: 600,
scale: 1,
buttons: {
  contextButton: {
    menuItems: [
      'printChart',
      'separator',
      'downloadPNG',
      'downloadJPEG',
      'downloadPDF',
      'downloadSVG',
      'separator',
      'downloadCSV',
      'downloadXLS',
      'separator',
      {
        text: 'Delete graph',
        onclick: function() {
           deleteGraph(this.renderTo.id);
        }
      }
    ]
  },
  customButton: {  //Add Serie Button
    onclick: function (e) {
      if( $(this.renderTo).hasClass("is-monitoring") ){
        toastr.error("Unable to add a new serie during monitoring.");
        return false;
      }

      toggleFiltreWidthFromChart(this);
    },
    className: UI_IDs.customHighChartsAddPointButton,
    symbol: 'deleteGraphe',
    symbolStroke: 'red'
  },
  j_1: {
    text: "YTD",
    className: UI_IDs.customHighChartsZoomButton + " j_1",
    onclick: function (event) {
        if (this.series.length < 0)
            return false;

      var max = this.xAxis[0].dataMax,
          range = 24 * 3600 * 1000;  //one day
      this.xAxis[0].setExtremes(max - range, max);
    }
  },
  j_7: {
    text: "Last week",
    className: UI_IDs.customHighChartsZoomButton + " j_7",
    onclick: function (event) {
        if (this.series.length < 0)
            return false;

      var max = this.xAxis[0].dataMax,
          range = 7 * 24 * 3600 * 1000;  //7 days
      this.xAxis[0].setExtremes(max - range, max);
    }
  },
  j_30: {
    text: "30 derniers jours",
    className: UI_IDs.customHighChartsZoomButton + " j_30",
    onclick: function (event) {
        if (this.series.length < 0)
            return false;

      var max = this.xAxis[0].dataMax,
          range = 30 * 24 * 3600 * 1000;  //30 days
      this.xAxis[0].setExtremes(max - range, max);
    }
  },
  j_all: {
    text: "See All",
    className: UI_IDs.customHighChartsZoomButton + " j_all",
    onclick: function (event) {
      this.zoomOut();
    }
  },
  remove_last_annotation: {
    symbol: removeLastAnnotation,
    symbolX:19,
    symbolY:19,
    _titleKey: "removeLastAnnotation",
    className: UI_IDs.removeLastAnnotation_base64,
    onclick: function (event) {
      if (this.annotations.length < 1)
        return false;

      this.annotations[this.annotations.length-1].destroy();
      this.annotations.splice(this.annotations.length-1, 1);
    }
  }
}
}

这是定义“默认”配置的大型JS对象的一部分,当用户希望创建新图形时,我调用(并存储)

charts.push(Highcharts.chart(graphId, config, function(){
   ...
}));

0 个答案:

没有答案