带有类别代替极性坐标的高级图表CSV出口高清图表CSV



我已经实现了一个极图表,其中每个系列的4个值对应于4个类别。当我导出图表CSV时,category列包含极性坐标。我想用相应的类别名称替换它们。我该怎么做?

将类别添加到每个系列中,没有效果。我还尝试在Xaxis中添加类别属性,但没有影响。xaxis.label格式化成功返回每个数据极性坐标的类别名称。

const options = {
  chart: {
    polar: true,
  },
  title: {
    text: '',
  },
  tooltip: {
    valueDecimals: 2,
    headerFormat: '<br/>',
  },
  legend: {},
  pane: {
    startAngle: 0,
    endAngle: 360,
  },
  xAxis: {
    tickInterval: 45,
    min: 0,
    max: 360,
    labels: {
      // eslint-disable-next-line
      formatter: function() {
        switch (this.value) {
          case 45:
            return '<b>Experience</b>'
          case 135:
            return '<b>Frictionless</b>'
          case 225:
            return '<b>Low Price</b>'
          case 315:
            return '<b>Brand</b>'
          default:
            return ''
        }
      },
    },
  },
  yAxis: {
    min: 0,
    max: 10,
    labels: {
      format: '{}',
    },
  },
  plotOptions: {
    series: {
      pointStart: 45,
      pointInterval: 90,
    },
    column: {
      pointPadding: 0,
      groupPadding: 0,
    },
  },
  series: kahnSeries,
}

您需要使用categories属性,但是没有以下选项:pointIntervalpointStartminmax

xAxis: {
    categories: ['Experience', 'Frictionless', 'Low Price', 'Brand']
},

实时演示:http://jsfiddle.net/blacklabel/z8cm1p39/

API参考:https://api.highcharts.com/highcharts/xaxis.categories

为了避免更改图表的当前显示,我包装了GetCSV函数并替换了CSV类别值。如果有更简单的方法,请分享。

{
  (function (H) {
    H.wrap(H.Chart.prototype, 'getCSV', function (
      proceed,
      useLocalDecimalPoint
    ) {
      // Run the original proceed method
      const result = proceed.apply(
        this,
        Array.prototype.slice.call(arguments, 1)
      )
      const itemDelimiter = ','
      const lineDelimiter = 'n'
      const rows = result.split(lineDelimiter)
      let newResult = ''
      let rowCategories = false
      rows.forEach((row, rowIndex) => {
          const columns = row.split(itemDelimiter)
          if (rowIndex === 0 && columns[0] === '"Category"') {
            rowCategories = true
          }
          if (rowIndex > 0 && rowCategories) {
            let newRow = formatter(columns[0])
            columns.forEach((column, columnIndex) => {
              if (columnIndex > 0) {
                newRow += itemDelimiter
                newRow += column
              }
            })
            newResult += newRow
          } else {
            newResult += row
          }
          if (rowIndex < rows.length - 1) {
            newResult += lineDelimiter
          }
        }
      )
      return newResult
    })
  }(Highcharts))
}

最新更新