highcharts -股票工具图表的保存图表按钮不保存当前选择的范围选择器

cwtwac6a  于 2023-01-13  发布在  Highcharts
关注(0)|答案(1)|浏览(136)

可以在此处描述功能:save chart button of stock tool chart not working in highcharts是否同时保存当前选定的范围选择器?

gwbalxhn

gwbalxhn1#

最简单的解决方案似乎是覆盖默认的saveChart按钮功能。在下面的例子中,保存所有指标和x轴极值应该可以正常工作。

const savedOptions = localStorage.getItem(['highcharts-chart']);
  const baseOptions = {...};

  H.stockChart('container', H.merge({
    navigation: {
      bindings: {
        saveChart: {
          init: function(button) {
            var navigation = this,
              chart = navigation.chart,
              annotations = [],
              series = [],
              xAxis = [],
              yAxis = [];

            annotations = chart.annotations.map(annotation => annotation.userOptions);

            chart.series.forEach(s => {
              if (!s.options.isInternal) {
                series.push(s.userOptions);
              }
            });
            chart.yAxis.forEach(axis => {
              if (axis.userOptions.className !== 'highcharts-navigator-yaxis') {
                yAxis.push(axis.userOptions);
              }
            });
            chart.xAxis.forEach((axis, index) => {
              if (!axis.options.isInternal) {
                xAxis.push(axis.userOptions);
                xAxis[index].min = axis.userMin;
                xAxis[index].max = axis.userMax;
              }
            });

            H.win.localStorage.setItem('highcharts-chart', JSON.stringify({
              series,
              annotations,
              yAxis,
              xAxis
            }));
            H.fireEvent(this, 'deselectButton', {
              button
            });
          }
        }
      }
    }
  }, savedOptions ? JSON.parse(savedOptions) : baseOptions));

相关问题