Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Realtime changes on PieChart #47

Closed
ruzovvo opened this issue Dec 4, 2015 · 12 comments
Closed

Realtime changes on PieChart #47

ruzovvo opened this issue Dec 4, 2015 · 12 comments
Labels

Comments

@ruzovvo
Copy link

ruzovvo commented Dec 4, 2015

Hi, I'm trying to use PieChart and I set
PrimaryValues="{Binding VM.Obj.Prop, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"

VM.Obj.Prop is a property:
public List Prop
{
get {return _prop;}
set {
_prop = value;
RaisePropertyChanged(() => Prop)
}
}

So in RaisePropertyChanged() I generate PropertyChanged event but chart doesn't change. only If I resize the window it will be redrawn.
Am I doing everything right or I miss smth?

@beto-rodriguez
Copy link
Collaborator

You don't need to raise property changed event, Live charts should detect automatically the changes, there is actually one exmaple included in test project, you can clone the repo to see it, or watch it here:

XAML

https://github.com/beto-rodriguez/Live-Charts/blob/master/ChartsTest/Pie%20Examples/MvvmPie.xaml

Code Behind

https://github.com/beto-rodriguez/Live-Charts/blob/master/ChartsTest/Pie%20Examples/MvvmPie.xaml.cs

Hope it helps, if this does not solves your issue please let me know.

@beto-rodriguez
Copy link
Collaborator

Forgot to mention that VM.Obj.Prop should be an observable collection, otherwise it wont update automatically, try instead

public ObservableCollection Prop {get;set;}

@gregsdennis
Copy link
Contributor

If you are editing the existing collection, you don't need to raise PropertyChanged. If you are reassigning the property, you do, and the control needs to respond to it to redraw.

Probably just needs a handler in the dependency property.

@beto-rodriguez
Copy link
Collaborator

it already has a handler in the dependency property.

@ruzovvo
Copy link
Author

ruzovvo commented Dec 6, 2015

Hi again. I tried what you've suggested with ObservableCollection. Now it works almost fine. Thank you for it.
But there are still 2 problems I'd like to avoid:

  1. each redraw is being processed from initial state but not from the previous state of collection
  2. look at pic attached. After redraw I have artifact numbers left from previous collection state. Sometimes these artifacts are being collected during several redraws so my numbers look like mess. I marked it with arrows
    piechart

@beto-rodriguez
Copy link
Collaborator

I will try to force this bug, can you please show me some parts of your code, So it can be easier for me?

@ruzovvo
Copy link
Author

ruzovvo commented Dec 6, 2015

public ObservableCollection Spectrum
{
get { return _spectrum; }
set
{
_spectrum = value;
RaisePropertyChanged(() => Spectrum);
}
}

Modification happens 1 time per second:

Spectrum.Clear();
Spectrum.Add(val1);
Spectrum.Add(val2);
Spectrum.Add(val3);
Spectrum.Add(val3);

@ruzovvo
Copy link
Author

ruzovvo commented Dec 6, 2015

Can you say smth about my 1st question regarding redrawing from initial state?

@beto-rodriguez
Copy link
Collaborator

the easiest solution, since you are updating the chart each second should be to disable animations, Set the DisableAnimation Property to ttue in your Pie Chart, right now pie chart only support full redraw animation, to support animation that starts from current state it is necesary to do an important improvements to PieSerie class, I will open a new issue to add this in a future, by now disable animations please.

@ruzovvo
Copy link
Author

ruzovvo commented Dec 7, 2015

Beto, I've found 1 more problem.
this approach does not work:

<liveCharts:PieChart Name="Spectrum" Grid.Row="0" Grid.Column="0" DisableAnimation="True">
    <liveCharts:PieChart.Series>
        <liveCharts:PieSeries Title="Maria" PrimaryValues="{Binding Obj.Prop}"
                 Labels="{Binding Obj.PropDesc}" />
    </liveCharts:PieChart.Series>
</liveCharts:PieChart>

updates don't come. but if I bind like this:

<liveCharts:PieChart Name="Spectrum" Grid.Row="0" Grid.Column="0" DisableAnimation="True" Series="{Binding PropSeries}"/>

and manually do in viewmodel:

PropSeries.Add(new PieSeries() { PrimaryValues = Obj.Prop });

where PropSeries is and ObservableCollection then piechart will be updating on collection Obj.Prop changes. Please take a look

@beto-rodriguez
Copy link
Collaborator

@ruzovvo I will take a look, it seems that the handler is not beeing attached if you initialize it with XAML, I will take a look and let you know as soon as possible, Thanks for reporting

@ZaJra
Copy link

ZaJra commented Dec 7, 2019

ruzovvo do you still have the code for realtime pi chart?

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

No branches or pull requests

4 participants