beto-rodriguez / LiveCharts2

Simple, flexible, interactive & powerful charts, maps and gauges for .Net, LiveCharts2 can now practically run everywhere Maui, Uno Platform, Blazor-wasm, WPF, WinForms, Xamarin, Avalonia, WinUI, UWP.
https://livecharts.dev
MIT License
4.39k stars 574 forks source link

LiveCharts 2 CartesianChart does not render when placed in an Avalonia UserControl #1581

Closed kvenkataraman closed 2 months ago

kvenkataraman commented 2 months ago

Bug (?): Not entirely convinced this is a bug, but perhaps how the DataContext for the charts is being resolved. In any case ...

Embedded a CartesianChart in an AvaloniaUserControl (SubControlView/SubControlViewModel) and placed that on the MainView. The chart does not render when embedded in the control, but will render if placed directly on the MainView/MainViewModel.

To Reproduce Steps to reproduce the behavior:

  1. Create an Avalonia UserControl and associated ViewModel (e.g. SubControlView/SubControlViewModel).
  2. Create an ISeries[] property with dummy data, and bind that to the control's CartesianChart.
  3. Add SubControlView to the main view and run the app.
  4. See that the chart does not render.
  5. Remove control, and add an ISeries and CartesianChart directly to MainView/MainViewModel.
  6. Observe that the chart renders.

Expected behavior Expect charts to render whether from a control or main window.

Desktop (please complete the following information):

Additional context Have tried ReflectionBinding, and setting RelativeSource but to no avail. Possibly related to this: https://github.com/beto-rodriguez/LiveCharts2/issues/1566

kvenkataraman commented 2 months ago

UPDATE:

Looks like you need to set the Height and Width properties in order for the chart to render if it's on a sub-control. Is this expected? The samples don't explicitly call out having to set those properties.

beto-rodriguez commented 2 months ago

Hello.

That depends on the layout the chart is placed on.

LiveCharts controls do not set an initial size, it is up to the developer to build that, maybe in a Future we will consider adding min height and width constraints to prevent this confusion.