简体   繁体   English

将数据添加到 Lightning Chart 中的现有图表系列

[英]Add data to existing chart series in Lightning Chart

I have a react js application in which, I have used a point series to plot data in chart.我有一个 react js 应用程序,在其中,我使用了一个点系列来表示图表中的 plot 数据。

I got the chart to display.我得到了要显示的图表。 But, I want real time data to be binded to chart.但是,我希望将实时数据绑定到图表。

Eg: If a chart contains 10 points on loading, it is marked to chart.例如:如果图表在加载时包含 10 个点,则将其标记为图表。 Then in 5 sec interval, I will be getting datas from socket which I have to add to the existing chart.然后在 5 秒的间隔内,我将从套接字获取数据,我必须将其添加到现有图表中。 So now, there has to be 15 points in charts and the chart has to move from left to right as the data comes in.所以现在,图表中必须有 15 个点,并且随着数据的输入,图表必须从左向右移动。

Here is my code that is used to bind data at the starting这是我的代码,用于在开始时绑定数据

    import {
  lightningChart,
  AxisTickStrategies,
  LegendBoxBuilders,
  Themes,
  PointShape,
  translatePoint,
  AxisScrollStrategies
} from "@arction/lcjs";


const dateOrigin = new Date(startingDate);
    const chart = lightningChart()
      .ChartXY({
        container: id,
        theme: Themes.lightNew,
        columnIndex: 0,
        columnSpan: 1,
        rowIndex: 0,
        rowSpan: 1
      })
      .setTitle(id.split(" ")[1]);

    const originDate = new Date(moment().subtract(1, 'days'))

    const xAxis = chart.getDefaultAxisX().setTickStrategy(
      // Use DateTime TickStrategy for this Axis
      AxisTickStrategies.DateTime,
      // Modify the DateOrigin of the TickStrategy
      // (tickStrategy) => tickStrategy.setDateOrigin(dateOrigin)
      (tickStrategy) => tickStrategy.setDateOrigin(originDate)
    );

    const yAxis = chart
      .getDefaultAxisY()
      .fit(true)
      .setScrollStrategy(undefined)
      .setInterval(-20, 20)
      .setTitle("");

    const series = chart
      .addPointSeries({
        xAxis: xAxis,
        yAxis: yAxis,
        pointShape: PointShape.Circle
      })
      .setName("Actual");

const dataFrequency = ((((600 - 600 * 250) - (60 * 60 * 100)) - (1000 * 2)) - 900)
      //0-24 hrs
      chart.getDefaultAxisX().setInterval(92 * dataFrequency, 60);

series.add(
      sensorData.map((point) => ({
        //x: new Date(point.x).getTime() - startingDate.getTime(),

        x: new Date(point.x).getTime() - new Date(startingDate).getTime(),
        y: point.y, // * 1000,
      }))

    );

Please let me know how the incomming data from socket has to be added to the existing points in charts.请让我知道如何将来自套接字的传入数据添加到图表中的现有点。

Thanks in Advance.提前致谢。

You can append more data points to a PointSeries with another call to add method, same way as you use it for the initial data.您可以 append 将更多数据点指向一个PointSeries并调用另一个add方法,就像您将其用于初始数据一样。

So keep a reference to the PointSeries object and when you receive the new data from websocket just use the add method in exactly same way as you did before to append the data on top of the previous data points.因此,请保留对PointSeries object 的引用,当您从 websocket 收到新数据时,只需按照与之前对 append 顶部数据点完全相同的方式使用add方法。

For "moving the chart from left to right as data points come in", you should configure the X axis scroll strategy to be progressive.对于“在数据点进入时从左向右移动图表”,您应该将 X 轴滚动策略配置为渐进式。 Please refer to this ECG chart example for code reference (line 44, chart.getDefaultAxisX()... ).请参阅此ECG 图表示例以获取代码参考(第 44 行, chart.getDefaultAxisX()... )。

For means of Stack Overflow historical completeness I'll also add the highlighted code line here:对于 Stack Overflow 历史完整性,我还将在此处添加突出显示的代码行:

// Configure X Axis as progressive scrolling with value interval of 1000
chart.getDefaultAxisX().setInterval(0, 1000).setScrollStrategy(AxisScrollStrategies.progressive)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM