[使用Highcharts v8.0将隐藏的系列包含在导出的CSV中

问题描述 投票:0回答:1

我有一个正常工作的Highcharts条形图,带有2个系列,可以正确导出为CSV。我添加了一个隐藏的ROUND系列,该系列应包含在导出的CSV数据中。将includeInDataExport属性设置为true可以实现此目的。但是,这对我不起作用,并且我还没有找到显示如何正确使用此属性的示例。

这里是当前图表选项。

{
  chart: {
    type: "bar"
    marginTop: 30
    spacingRight: 50
    style: {
      fontWeight: "400",
      fontFamily: "Montserrat"
    }
  },
  title: {
    text: ""
  }
  xAxis: {
    categories: Array(7),
    lineWidth: 1
  }
  yAxis: {
    min: 0,
    lineWidth: 1
  }
  legend: {
    reversed: true,
    itemStyle: {
    }
  }
  tooltip: {
    headerFormat: "COMPANY: {point.x}<br/>",
    pointFormat: "{series.name}: <b>${point.y}</b>"
  }
  plotOptions: {
    bar: {
      dataLabels: {
        enabled: true
      },
      includeInDataExport: true
    },
    series: {
      colorByPoint: true,
      includeInDataExport: true
    }
  }
  series: [
    {
      name: "ROUND",
      data: [
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ],
      visible: false,
      showInLegend: false
    },
    {
      name: "P2",
      data: [
        230.3,
        228.25,
        217.72,
        243.34,
        235.56,
        205.73,
        252.83
      ]
    },
    {
      name: "P1",
      data: [
        115.15,
        115.58,
        104.2,
        115.58,
        113.34,
        101.27,
        121.3
      ]
    }
  ]
}}
highcharts
1个回答
0
投票

[似乎当前的Highcharts逻辑不允许从可见设置为false的序列中获取CSV数据,请参阅:https://github.com/highcharts/highcharts/blob/master/js/modules/export-data.src.js#L350

从这段代码来看,过去似乎有人因为某种错误而有目的,但是我不确定现在该怎么考虑。如果需要,可以在Highcharts Github问题频道中启动线程:https://github.com/highcharts/highcharts/issues

作为一种解决方法,我建议仅在没有有关系列可见性的这种条件的情况下使用此逻辑:

演示:https://jsfiddle.net/BlackLabel/n5za1q3x/

   this.series.forEach(function(series) {
     var keys = series.options.keys,
       pointArrayMap = keys || series.pointArrayMap || ['y'],
       valueCount = pointArrayMap.length,
       xTaken = !series.requireSorting && {},
       xAxisIndex = xAxes.indexOf(series.xAxis),
       categoryAndDatetimeMap = getCategoryAndDateTimeMap(series, pointArrayMap),
       mockSeries, j;
     if (series.options.includeInDataExport !== false &&
       !series.options.isInternal // #55
     ) {
.........
© www.soinside.com 2019 - 2024. All rights reserved.