0

I want to show a Line Series using WinRT XAML toolkit for Windows Phone 8.1 I have the following code but nothing appears on the screen:(I am using MVVM Light for implementing MVVM) Website.xaml

    <Grid Grid.Row="0" Background="Black" Margin="20,20,10,10">
        <charting:LineSeries x:Name="LineSeries" Height="250" Width="320" ItemsSource={Binding DataPoints} IndependentValueBinding="{Binding X}" DependentValueBinding="{Binding Y}">

        </charting:LineSeries>
    </Grid>

In the corresponding view model I have

    public class WebsiteViewModel:ViewModelBase
    {
          private List<DataPoint> _datapoints;
          public List<DataPoint> DataPoints
          {
               get
               {
                  return _datapoints;
               }
               set
               {
                    if(_datapoints!=value)
                    {
                           _datapoints=value;
                           RaisePropertyChanged("DataPoints");
                    }
               }
         }

        public WebsiteViewModel()
        {
                if(IsInDesignMode)
                {
                        DataPoint p1=new DataPoint(){X="ABC",Y=21.23};
                        DataPoint p2=new DataPoint(){X="XYZ",Y=34.56};
                        DataPoints=new List<DataPoint>();
                        DataPoints.Add(p1);
                        DataPoints.Add(p2);
               }
        }
    }

And DataPoint class is defined below:

  public class DataPoint:ObservableObject
 {
    private string _x;
    public string X
    {
        get
        {
            return _x;
        }
        set
        {
            if(_x!=value)
            {
                _x = value;
                RaisePropertyChanged("X");
            }
        }
    }

    private double _y;

    public double Y
    {
        get
        {
            return _y;
        }
        set
        {
            if(_y!=value)
            {
                _y = value;
                RaisePropertyChanged("Y");
            }
        }
    }

}

But I can't see any data at design time. I have set the DataContext in XAML using the ViewModelLocator property. Is there something wrong with my code? Does WinRTXAML toolkit actually work with WP 8.1? If not, can anyone point me to any other open-source chart library for WP 8.1? I've looked up Sparrow, but it is only WP8 compatible.

Sridhar
  • 837
  • 1
  • 10
  • 21
  • Does it work at run time? The controls don't support design time and most of them might not behave well in the design view. – Filip Skakun Nov 07 '14 at 03:17
  • Thanks for the information. I managed to get it working at runtime from code-behind. I still have a problem doing it binding it in XAML. Do I need to specify the `IndependentValueBinding` property or `IndependentValuePath` property in XAML? – Sridhar Nov 07 '14 at 04:02
  • Sorry, I'd have to try and debug myself. – Filip Skakun Nov 07 '14 at 08:36

1 Answers1

0

I got this blog it works perfectly for my windowsRT phone 8.1 XAML http://eren.ws/2013/10/15/using-graphs-and-charts-in-windows-store-apps-boredom-challenge-day-11/ Your xaml should be :

xmlns:charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"
xmlns:Series="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"
xmlns:datavis="using:WinRTXamlToolkit.Controls.DataVisualization"

<Grid Grid.Row="0" Background="Black" Margin="20,20,10,10">
    <charting:Chart x:Name="LineSeries">
                <charting:Chart.Series>
                    <Series:LineSeries IndependentValuePath="{Binding X}" DependentValuePath="{Binding Y}">

                    </Series:LineSeries>
                </charting:Chart.Series>
            </charting:Chart>
</Grid>

Inside the code

using WinRTXamlToolkit.Controls.DataVisualization.Charting;
//something like this, your listdata
(LineSeries.Series[0] as LineSeries).ItemsSource = DataPoints; 

It still buggy also, in my case the chart shows while debugging, but the page that contains the chart can not be navigated after i release it,

I will update my answer after I figure it out or you can also follow this topic :http://goo.gl/GyCSxg.

Ganesh Cauda
  • 969
  • 6
  • 21