在 highcharts 中组合图形

Combining graphs in highcharts

我正在尝试根据来自服务器的动态数据绘制两个折线图。这些图表是基于比较的图表,其中数据点随时间进行比较

我正在尝试将其中一张图制作为面积图,而另一张仍然是折线图。 在我的例子中,Current 应该是折线图,而 Baseline 应该是面积图

沙盒:https://codesandbox.io/s/react-line-chart-n9g6o?file=/src/LineChart.js

这是我试过的

import * as React from "react";
import Highcharts from "highcharts";
import HighchartsReact from "highcharts-react-official";
import HC_exporting from "highcharts/modules/exporting";
HC_exporting(Highcharts);

function LineChart(props) {
  let chartOptions = {
    chart: {
      type: "line",
      height: props.height
    },
    credits: false,
    exporting: { enabled: false },
    title: {
      text: ""
    },
    legend: {
      align: "center",
      verticalAlign: "bottom",
      x: 0,
      y: 0
    },
    tooltip: {
      shared: true,
      useHTML: true,
      formatter: function() {
        let self = this;
        let formattedString = "<small></small><table>";
        self.points.forEach(elem => {
          formattedString +=
            '<tr><td style="color: {series.color}">' +
            elem.series.name +
            ": </td>";
          formattedString +=
            '<td style="text-align: right"><b>' + elem.y + "</b></td></tr>";
        });
        return formattedString;
      }
    },
    colors: props.legendColor,
    xAxis: {
      visible: false
    },
    yAxis: {
      visible: true,
      step: 1
    },
    plotOptions: {
      column: {
        dataLabels: {
          enabled: true,
          crop: false,
          overflow: "none"
        }
      },
      line: {
        marker: {
          enabled: false
        }
      }
    },
    series: props.chartData
  };
  return <HighchartsReact highcharts={Highcharts} options={chartOptions} />;
}

export default LineChart;

有人可以帮我吗?帮助将不胜感激。

您只需要在系列配置对象中设置适当的type

data.push({
  name: "BASELINE",
  type: 'area',
  data: old,
  keys: ["x", "y", "ots"]
});

现场演示: https://codesandbox.io/s/react-line-chart-2ohem?file=/src/index.js

API参考:https://api.highcharts.com/highcharts/series.area.type