You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using MAUI and I have a ChartView that has a rendered Chart, but at a later point in time, the data changes.
I can't bind the Entries of any type of Chart, so I opted to bind the ChartView.ChartProperty and generate a completely new chart, but this method will not clear the canvas before redrawing, it will simply draw an additional copy of the chart somewhere on the canvas, it does in fact seem to attempt to avoid drawing over the previous chart if possible.
The canvas is not accessible, so I can't manually erase it.
In the context where the update comes in, I do not know the exact subclass of the current Chart. Chart itself has no Entries property, so I can't change that.
Even if I first change the ChartView.Chart to null, the canvas is not erased.
UPDATE:
Turns out the canvas is only erased when you set the Chart to null. However when you use MVVM and bindings in MAUI, it won't work well together:
View model value changes
Set the value to null to clear canvas
Set the value to draw a new graph
Binding fires twice, both passing the latest value
Graph gets drawn on top of the previous drawing
I tried a different step 2 where I set the ChartView.Graph to null, but that doesn't work either.
I managed to get it to work when I introduced a delay between 2 and 3, but that's ugly and not guaranteed to work.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
How do I update the data of a
Chart
?I'm using MAUI and I have a
ChartView
that has a renderedChart
, but at a later point in time, the data changes.I can't bind the
Entries
of any type ofChart
, so I opted to bind theChartView.ChartProperty
and generate a completely new chart, but this method will not clear the canvas before redrawing, it will simply draw an additional copy of the chart somewhere on the canvas, it does in fact seem to attempt to avoid drawing over the previous chart if possible.The canvas is not accessible, so I can't manually erase it.
In the context where the update comes in, I do not know the exact subclass of the current
Chart
.Chart
itself has noEntries
property, so I can't change that.Even if I first change the
ChartView.Chart
tonull
, the canvas is not erased.UPDATE:
Turns out the canvas is only erased when you set the
Chart
tonull
. However when you use MVVM and bindings in MAUI, it won't work well together:null
to clear canvasI tried a different step 2 where I set the
ChartView.Graph
tonull
, but that doesn't work either.I managed to get it to work when I introduced a delay between 2 and 3, but that's ugly and not guaranteed to work.
Beta Was this translation helpful? Give feedback.
All reactions