Xamarin Microcharts and when should I create the Chart instance?

Xamarin Microcharts and when should I create the Chart instance?



I have been trying to integrate Microcharts within my Xamarin project. As I wanted them to exist within a listview, I added them to a Model-View-Class and instantiated the BarChart class right there:


public class ChangeOverview


Chart _SuccessChart = null;
public Chart SuccessChart get;
List<Entry> _entries = new List<Entry>()

new Entry(200)

Label = "January",
ValueLabel = "200",
Color = SKColor.Parse("#FF0033")
,
new Entry(300)

Label = "February",
ValueLabel = "300",
Color = SKColor.Parse("#FF0000")
,
new Entry(400)

Label = "March",
ValueLabel = "400",
Color = SKColor.Parse("#AA0000")
,
;
public List<Entry> ChartEntries

get

return _entries;


public ChangeOverview(Change c)

_SuccessChart = new BarChart()

Entries = _entries
;




So in my ContentPage.xaml.cs, I did the following:


public ChangeList ()

InitializeComponent ();
Debug.WriteLine("### Changes: " + User.LoggedUser.AllMyChanges.Count);


foreach (Change c in User.LoggedUser.AllMyChanges)

list.Add(new ChangeOverview(c));


TestChart.Chart = list[0].SuccessChart;



This should have been pretty straight forward, however this did not show me a chart. As I searched around, I found out that I should put the code within my OnAppearing method:


protected override void OnAppearing()

base.OnAppearing();
TestChart.Chart = list[0].SuccessChart;
TestChart.Chart = new BarChart() Entries = list[0].ChartEntries ;




Just assigning the chart doesn't help me, I really have to instantiate the BarChart() within this method.



Is there another way? Can I just somehow refresh the chart? Or do I really have to instantiate the Chart here in the OnAppearing method?



Thanks in advance!






Does anybody have an idea on why it behaves like this?

– Wolffi82
Sep 19 '18 at 18:08




0



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)