我需要创建一个包含多个系列的(WP7)图表。我试图想象的数据:
F.ex跟随集合,包含UserName,Date,Points:
数据中可以有两个以上的用户。
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
mdChart.Series.Add(MDSeries);
mdChart.Title = "Statistics";
MDSeries.SetBinding(ColumnSeries.ItemsSourceProperty, new Binding());
MDSeries.ItemsSource = lCompetitionStats;
MDSeries.DependentValuePath = "Points";
series.IndependentValuePath = "Date";
MDSeries.IndependentValuePath = "UserName";
<controls:PanoramaItem Header="mdscores">
<Grid>
<charting:Chart x:Name="mdChart" Foreground="Blue" Background="Black">
<charting:ColumnSeries Background="Black"/>
</charting:Chart>
</Grid>
</controls:PanoramaItem>
因此,我有X轴上的用户和Y轴上的点。我需要X轴上的日期,Y轴上的点和earch用户的单独系列。如何创建/填充这样的图表运行时?
答案 0 :(得分:0)
尝试以下方法:
public class ColumnChartValues
{
#region Variables
public string Label { get; private set; }
public double Value { get; private set; }
#endregion
#region Constructor and Initialization
public ColumnChartValues()
{
Label = string.Empty;
Value = 0;
}
public ColumnChartValues(string label, double value)
{
Label = label;
Value = value;
}
#endregion
}
public partial class StatsPage : Page
{
public ObservableCollection<ColumnChartValues> ColumnChartDatabase { get; private set; }
public StatsPage()
{
DataContext = this;
InitializeColumnChart();
}
private void InitializeColumnChart()
{
mdChart.Title = "Statistics";
ColumnChartDatabase = new ObservableCollection<BarChartValues>();
ColumnChartDatabase.Add(new ColumnChartValues("Value One: ", 1));
ColumnChartDatabase.Add(new ColumnChartValues("Value Two: ", 2));
ColumnChartDatabase.Add(new ColumnChartValues("Value Three: ", 3));
}
}
<charting:Chart x:Name="mdChart" Foreground="Blue" Background="Black">
<charting:ColumnSeries Background="Black" ItemsSource="{Binding ColumnChartDatabase}" IndependentValueBinding="{Binding Label}" DependentValueBinding="{Binding Value}"/>
</charting:Chart>
您必须编辑ColumnChartValues图表以满足您的需求