This project is read-only.

How to use SparrowChart without MVVM?

Feb 1, 2014 at 2:21 PM
I am getting into SparrowChart and I set up the XAML like the tutorial wants me to
<sparrow:SparrowChart 
          x:Name="Chart"
          Margin="7,73,16,11"
          Foreground="#FF666666">
    <sparrow:SparrowChart.XAxis>
        <sparrow:LinearXAxis />
    </sparrow:SparrowChart.XAxis>
    <sparrow:SparrowChart.YAxis>
        <sparrow:LinearYAxis />
    </sparrow:SparrowChart.YAxis>
    <sparrow:LineSeries Stroke="#FF666666"
        PointsSource="{Binding Collection}"
        XPath="X"
        YPath="Y" />
</sparrow:SparrowChart>
But now I want to add the points of the chart not via MVVM.
But since SparrowChart doesn't have a ItemSource property, I am wondering how I can add points to the chart by hand in C#.

In my class I have
public ObservableCollection<GraphPoint> Collection 
    = new ObservableCollection<GraphPoint>();

public class GraphPoint
{
    public double X { get; set; }
    public double Y { get; set; }

    public GraphPoint (double x, double y)
    {
        X = x;
        Y = y;
    }     
}

//Page, where the chart is in

public Stats()
{
    InitializeComponent();

    for (int i = 0; i < 10; i+=1)
    {
        GraphPoint g = new GraphPoint(i, i+1);
        Collection.Add(g);
    }
}
But the chart isn't adding the points.
Feb 26, 2014 at 11:26 PM
I was able to do it in code like this:
var series = new AreaSeries();
series.XPath = "X";
series.YPath = "Y";
series.PointsSource = GetPoints();

Chart.Series.Add(series);