microcharts-dotnet / Microcharts

Create cross-platform (Xamarin, Windows, ...) simple charts.
MIT License
2.02k stars 361 forks source link

[Bug] ArgumentOutOfRangeException - when using updating multiseries and different line chart lengths #279

Closed brett-estabrook closed 3 years ago

brett-estabrook commented 3 years ago

Describe the bug We have a line chart with multiple lines, this is connected to Signal R so we get updated points periodically. Because it line is updated separately they don't always have the same length of points. We currently have a patch where it just delays updating the chart until all lines have an equal number of points. My main problem with this solution is if an update takes a while all lines stop updating even if only one has a problem. Ideally the lines with more points continue to draw and the old ones just dead-end early.

I believe the problem is on this line: AxisBasedChart.cs#L208

Which platform and version is this for? iOS 14.5, this is the new 1.0 Beta version we're using on Xamarin Forms (Through NuGet).

To Reproduce Create a line chart with at least 2 lines and make one have fewer points that then other

Expected behavior I'd like it to stop drawing the line with fewer points, but continue drawing the line with more points.

AxisBasedChart.cs#L208

ChartSerie serie = Series.ElementAt(serieIndex);
if( i >= serie.Entries.Length ) continue; //I suspect adding this line would work for our use case.
ChartEntry entry = serie.Entries.ElementAt(i);
Seuleuzeuh commented 3 years ago

Hi @brett-estabrook, thanks for the feedback. When i've implemented this functionnality i've not think of this use case, it's a great idea.

Are you able to made a PR for trying this changes ? For a quick test, you can -in your PR- add this use case in the sample app include in this repo.

brett-estabrook commented 3 years ago

@Seuleuzeuh - I have some initial work at feature/279-dynamic-multiseries-linechart

However, I've noticed that the behavior of the horizontal axis which represents time is somewhat undefined. The second series simply draws points at the same labels of the first series even if the labels are different. It also brings up the point that at least for our situation the labels for each point won't necessarily match between the two series.

For our situation we may need to create a time specific chart where the horizontal axis is defined as a Date Range, and the points are interpolated between them. As we'd probably want labels every 5-10 seconds, but the point timestamps would not be rounded to 5-10 seconds.

For the purpose of a Pull Request, you'll want to look at these two changes to decide if you want to merge them. They do prevent the crash if the series lengths are not the same, and I could see someone wanting it to work for specific situations.

Sources/Microcharts/Charts/AxisBasedChart.cs Sources/Microcharts/Charts/LineChart.cs

Lastly, the example chart I made is still a WIP, I want to make better use of protected virtual void UpdateSeries(IEnumerable<ChartSerie> value)

brett-estabrook commented 3 years ago

So I was thinking a bit more about this, and I realized the underlying issue is support for null values (#36 ). I've taken a stab at that here:

https://github.com/brett-estabrook/Microcharts/tree/feature/36-null-value-support