Closed MajesticBevans closed 2 months ago
Note: simple workaround is just to always initialise YAxes collection with one element e.g. new Axis()
Hello and thanks for the report.
I think that there is no issue here, the concept of an axis is required to measure the chart, I mean a CartesianChart by concept requires both X and Y, we could consider this a limitation of the library but.... it is much better than hacking the concept of a Cartesian chart...
As you mentioned in your workaround, let's just make the system happy by adding and instance of both axes, that is a requirement for a chart to measure properly, actually by default Axes are initialized as you stated.
I will close this for now, I think this "issue" is understandable since it is a requirement by the Cartesian Coordinate system, feel free to let me know your opinion on this one.
I agree it makes sense that CartesianCharts should have both an X and Y axis in concept, but I think the behaviour of the library should probably be consistent on needing that, whether there is a legend displayed or not.
If YAxes is an empty collection, but the legend is hidden, there is no crash. If the legend is not hidden (even though there are no series plotted) there is a crash.
IMO, it should either crash in both cases, or in neither. I'd be interested to hear what others think.
@MajesticBevans I agree, the referenced commit will make it throw always!
Describe the bug When trying to add a legend to a cartesian chart in Avalonia (v11.1.1), an IndexOutOfRangeException is thrown within the livecharts dlls. This happens within the SKDefaultLegend.cs file, in the Draw method when trying to add the visual to the chart, and only seems to occur when the cartesian chart YAxes property is bound to an empty collection.
To Reproduce Steps to reproduce the behavior:
<lvc:CartesianChart LegendPosition="Right" YAxes="{Binding YAxes}" />
[ObservableProperty] private ObservableCollection<Axis> _yAxes = [];
Expected behavior Expect the app not to crash.
Desktop (please complete the following information):
Additional context Binding the YAxes to an empty collection is only a problem when I change the LegendPosition to not hidden, so I don't believe this should cause a problem. This crash occurs for all the LegendPositions except for hidden. I believe this is an issue with trying to draw the legend somewhere outside of the bounds of the chart itself. Perhaps because it is not accounting for the width of the axes labels? Not sure. The problem should be simple to recreate, and this may only be an Avalonia issue.
The same behaviour occurs when the YAxes collection is cleared mid-execution.