我正在寻找一种在我的 xaml 中绑定整个图表的方法。不仅是一个系列,而是整个图表。这是因为我需要动态地将多个系列添加到图表中。
XAML:
<chart:Chart DataContext="{Binding Path=FocusEnergyChart, UpdateSourceTrigger=PropertyChanged}"/>
C#:
public void DrawChart()
{
myChart = new Chart();
LinearAxis xAxis = new LinearAxis();
xAxis.Orientation = AxisOrientation.X;
xAxis.Title = "Energy";
LinearAxis yAxis = new LinearAxis();
yAxis.Orientation = AxisOrientation.Y;
yAxis.Title = "Focus";
myChart.Axes.Add(xAxis);
myChart.Axes.Add(yAxis);
myChart.Title = "Focus Energy - Chart";
foreach( string aKey in myGraphData.Keys)
{
BubbleSeries aSeries = new BubbleSeries();
aSeries.Title = aKey;
aSeries.ItemsSource = myGraphData[aKey];
aSeries.DependentValuePath = "Focus";
aSeries.IndependentValuePath = "Energy";
aSeries.SizeValuePath = "Size";
aSeries.SetResourceReference(Series.BackgroundProperty, "Background");
aSeries.SetResourceReference(BubbleSeries.LegendItemStyleProperty, "CustomLegendItemStyle");
aSeries.SetResourceReference(BubbleSeries.DataPointStyleProperty, "BubbleToolTipTemplate");
myChart.Series.Add(aSeries);
}
base.OnPropertyChanged("FocusEnergyChart");
}
public Chart FocusEnergyChart
{
get { return myChart; }
}
当我尝试运行此代码时,它只会显示一个空的 ChartArea。
我希望有一个人可以帮助我!
谢谢!