Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real-time data performance #43

Closed
smofe opened this issue Jan 7, 2022 · 6 comments
Closed

Real-time data performance #43

smofe opened this issue Jan 7, 2022 · 6 comments

Comments

@smofe
Copy link

smofe commented Jan 7, 2022

I have a project were I need to render multiple charts of incoming sensor data. The charts should be updated at least every 30ms and show up to 1000 data points at a time, as a line chart. Is this library suited for this use-case and capable of this performance?

Thanks for any tips.

@entronad
Copy link
Owner

entronad commented Jan 7, 2022

I think it is suite for your case. There are some optimizations for fast updating in this lib.

I believe your updating is triggered by setState in the widget tree, make sure to set rebuild: false, and changeData: true if the data is modified in the same list instance, then each time the widget updates, the chart will not rebuild the whole operators flow but only pulse data related operators and update nessasary figures. That makes it fast in data changing.

But to be careful, I suggest you to make some performace tests. 1000 points is not a problem at all, but 30ms is a rare requirement that I havent tried.

@entronad
Copy link
Owner

entronad commented Jan 7, 2022

I hope you could please feedback your result in this issue, whether this lib satisfy your demand at last.

@smofe
Copy link
Author

smofe commented Jan 7, 2022

Thanks for the quick response!
I tried to get it to work, but I am unable to update the chart. I feel like I am missing something obvious here. Do you see the mistake?

My code looks like this:

// timer that is started in initState and adds new data points to the data list
timer = Timer.periodic(const Duration(milliseconds: 30), (_) {
      if (data.length >= 1000) {
        data.removeAt(0);
      }
      setState(() {
        data.add(ChartData(counter, r.nextInt(1000)));
      });
      print(data[0]);
      counter++;
    });
Chart(
  rebuild: false,
  changeData: true,
  data: data,
  variables: {
    'index':
        Variable(accessor: (ChartData data) => data.index),
    'value':
        Variable(accessor: (ChartData data) => data.value)
  },
  elements: [
    LineElement(
        shape: ShapeAttr(value: BasicLineShape(smooth: true)))
  ],
  axes: [
    Defaults.horizontalAxis,
    Defaults.verticalAxis,
  ],
)

@entronad
Copy link
Owner

entronad commented Jan 8, 2022

The problem is caused by a bug, when you didn't create new instance of the data list but modified it, the changeData: true will not work.

It has been fixed in 0.8.0, please upgrade and try.

But I have to say usually we consider widget property as immutable and create new instance when setState in Flutter. That's why this bug is hardly to expose. I suggest you to do so.

@smofe
Copy link
Author

smofe commented Jan 11, 2022

Thank you! I got it working now.

First impressions are that performance is adequat, although it is pushing it to the limit. Pretty much comparable to Syncfusion Charts, which I used before. I've got some issues with stuttering where I don't know yet what causes the problem, but so far I think it's not related to this library, as similar issues occured with the Syncfusion one.

I will do further testing and report back when I know more.

@jiangweihu
Copy link

Thank you! I got it working now.

First impressions are that performance is adequat, although it is pushing it to the limit. Pretty much comparable to Syncfusion Charts, which I used before. I've got some issues with stuttering where I don't know yet what causes the problem, but so far I think it's not related to this library, as similar issues occured with the Syncfusion one.

I will do further testing and report back when I know more.

Hello, I'm working on something similar, updating the data every second and then plotting a line graph of the data in real time, can you share your code with me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants