Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

xamarin forms labs chart mvvm

$
0
0

Hi every body, i'm trying hard to bind my chart's data source without any success.

If i put my DataPoints in xaml, it works. If i use binding, i get an error. I 'd like to use the pie chart.

Here is the xaml missing that xamarin's forum input refuse :

<charting:Chart
x:Name="PieChart"
WidthRequest="290"
HeightRequest="290"
BackgroundColor="{x:Static styles:ColorsResource.COULEUR_TRANSPARANT}"
DataSource="{Binding ReponsesChart, Mode=OneWay}">
        <charting:Chart.Series>
                <charting:Series Type="Pie"/>
            </charting:Chart.Series>

            <!--<charting:Chart.Series>
                <charting:Series Type="Pie">
                    <charting:Series.Points>
                        <charting:DataPoint Label="Jan"
                                            Value="20"
                                            Color="{x:Static styles:ColorsResource.Color1}" />
                        <charting:DataPoint Label="Feb"
                                            Value="7"
                                            Color="{x:Static styles:ColorsResource.Color2}" />
                        <charting:DataPoint Label="March"
                                            Value="33"
                                            Color="{x:Static styles:ColorsResource.Color3}" />
                        <charting:DataPoint Label="a"
                                            Value="12"
                                            Color="{x:Static styles:ColorsResource.Color4}" />
                        <charting:DataPoint Label="m"
                                            Value="28"
                                            Color="{x:Static styles:ColorsResource.Color5}" />
                    </charting:Series.Points>
                </charting:Series>
            </charting:Chart.Series>-->

The model :

public class ResultatReponseModel 
{
        public string Libelle { get; set; }     
        public int NombreVotants { get; set; }      
        public string Couleur { get; set; }
}

The viewModel :

(PLEASE XAMARIN GUYS FIX THE TAG CODE BECAUSE EVERY BODY IS TIRED OF EDITING EDITING UNTIL THE TEXT IS WELL FORMATED !! thank you so much ! i'd like this better than improve on ListView !! (no i'm kidding))

`

public class MyViewModel
{

public List Reponses { get; set; }

// the proxy property that returns the good type of object for the datasource of the chart.
public DataPointCollection ReponsesChart
{
get
{
var series = new DataPointCollection();
this.Reponses.ForEach(item => series.Add(new DataPoint(item.Libelle, item.NombreVotants) { Color = Color.FromHex(item.Couleur) }));
return series;
}
}
}`
Note the preview of my post always show me that my code is half cut...


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>