使用动态图表[动画图表]

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

我使用highcharts库创建了一个Areapline图表,并通过在几周的数据之间使用播放/暂停按钮进行过渡来使其具有动画效果

参考https://www.highcharts.com/blog/tutorials/176-charts-in-motion/

jsfiddle参考。 https://jsfiddle.net/larsac07/wkev75nL/?utm_source=website&utm_medium=embed&utm_campaign=wkev75nL

在上面的示例中,我们每周对图表进行动画处理

使用的数据集:

dataSequence = [
        {
            name: 'Week 1',
            data: [1, 2, 2, 1, 1, 2, 2]
        }, {
            name: 'Week 2',
            data: [6, 12, 2, 3, 3, 2, 2]
        }, {
            name: 'Week 3',
            data: [4, 5, 6, 5, 5, 4, 9]
        }, {
            name: 'Week 4',
            data: [5, 5, 6, 6, 5, 6, 6]
        }, {
            name: 'Week 5',
            data: [6, 7, 7, 6, 6, 6, 7]
        }, {
            name: 'Week 6',
            data: [8, 9, 9, 8, 8, 8, 9]
        }, {
            name: 'Week 7',
            data: [9, 10, 4, 10, 9, 9, 9]
        }, {
            name: 'Week 8',
            data: [1, 10, 10, 10, 10, 11, 11]
        }, {
            name: 'Week 9',
            data: [11, 11, 12, 12, 12, 11, 11]
        }
    ]

我不想更改图表在播放按钮上单击,我希望将第1周的数据点11个数据点动画化为相同的数据点,但第2周的y轴上的值不同]

xAxis = ["week1", "Week2", ..... ],
yAxis = [[1,2,3,4,5,6,7,8,9,10,11], [3,5,7,8,2,1,5,7,6,1,10], ....]

在播放按钮上,它会在week1之间转换,然后转到week 2,直到上周可用。

试图拥有类似此参考文献的内容。 https://aatishb.com/covidtrends/

此图表是使用该系列的数据集绘制的

Highcharts.chart("container", {
      chart: {
        type: "areaspline"
      },
      tooltip: {
        shared: true,
        valueSuffix: " units"
      },
      xAxis: {
        categories: [
          "Week 1",
          "Week 2",
          "Week 3",
          "Week 4",
          "Week 5",
          "Week 6",
          "Week 7"
        ]
      },
      yAxis: {
        title: {
          text: "Efficiency Index"
        }
      },
      legend: {
        layout: "horizontal",
        align: "right",
        verticalAlign: "top",
        x: 50,
        y: 50,
        floating: true,
        borderWidth: 1,
        backgroundColor:
          (Highcharts.theme && Highcharts.theme.legendBackgroundColor) ||
          "#FFFFFF"
      },
      plotOptions: {
        areaspline: {
          fillOpacity: 0.5
        }
      },
      credits: {
        enabled: false
      },
      series: [
        {
          name: "By week",
          data: dataSequence[value].data.slice()
        },
        {
          type: "spline",
          name: "Topic 1",
          data: [3, 2, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 2",
          data: [1, 5, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 3",
          data: [3, 7, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 4",
          data: [5, 1, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 5",
          data: [7, 3, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 6",
          data: [9, 2, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 7",
          data: [11, 8, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 8",
          data: [13, 11, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 9",
          data: [15, 7, 1, 3, 4, 7, 8]
        },
        {
          type: "spline",
          name: "Topic 10",
          data: [7, 5, 1, 3, 4, 7, 8]
        }
      ],
      title: {
        text: ""
      },
      subtitle: {
        text: "Efficiency Index of Topics"
      }
    });

此我的更新功能在反应

update(increment) {
    var input = $("#play-range")[0];
    var output = $("#play-output")[0];

    if (increment) {
      input.value = parseInt(input.value) + increment;
    }
    output.innerHTML = this.state.dataSequence[input.value].name;
    this.setState({
      value: input.value
    });
    if (input.value >= input.max) {
      // Auto-pause
      this.pause();
      this.setState(
        {
          value: 0
        },
        () => {
          output.innerHTML = this.state.dataSequence[0].name;
        }
      );
    }
  }

整个图表被立即绘制,我需要一些它应该转移的东西首先,当我单击播放按钮

时,它将绘制第1周的所有数据点,然后绘制第3周之后的第2周的数据

我使用highcharts库创建了一个Areapline图表,并通过在几周数据Ref之间进行播放/暂停按钮的过渡使其变得生动。 https://www.highcharts.com/blog/tutorials/176-charts-in -...

reactjs highcharts
1个回答
0
投票

您需要以一个空数据开始并在addPoint函数中使用update方法:

function update(increment) {
    var input = $('#play-range')[0],
        output = $('#play-output')[0],
        increment;

            chart.series[0].addPoint(dataSequence[input.value].data[actualPointIndex]);
    actualPointIndex += increment;

    if (actualPointIndex === 6) {
            actualPointIndex = 0;
        input.value = parseInt(input.value) + increment;
    }

    output.innerHTML = dataSequence[input.value].name; // Output value
    if (input.value >= input.max) { // Auto-pause
        pause($('#play-pause-button')[0]);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.