我想使用适用于Windows Phone 8.1的WinRT XAML工具包展示Line Series我有以下代码但屏幕上没有任何内容:(我使用MVVM Light实现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>
在相应的视图模型中我有
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);
}
}
}
DataPoint类定义如下:
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");
}
}
}
}
但我在设计时看不到任何数据。我使用ViewModelLocator属性在XAML中设置了DataContext。我的代码有问题吗? WinRTXAML工具包是否真的适用于WP 8.1?如果没有,任何人都可以指向WP 8.1的任何其他开源图表库吗?我查了一下Sparrow,但它只兼容WP8。
答案 0 :(得分:0)
我有这个博客 它适用于我的windowsRT手机8.1 XAML http://eren.ws/2013/10/15/using-graphs-and-charts-in-windows-store-apps-boredom-challenge-day-11/ 你的xaml应该是:
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>
代码内部
using WinRTXamlToolkit.Controls.DataVisualization.Charting;
//something like this, your listdata
(LineSeries.Series[0] as LineSeries).ItemsSource = DataPoints;
它仍然有问题,在我的情况下,图表显示调试时,但包含图表的页面在我发布后无法导航,
我会在弄清楚之后更新我的答案,或者您也可以关注此主题:http://goo.gl/GyCSxg。