我需要使用 ModernUI WPF 图表以编程方式设置图表系列标题。
我通过以下方式创建图表,以便轻松输入数据:
public class MainViewModel
{
public ObservableCollection<ChartData> Populations {get; set;}
public MainViewModel()
{
Populations = new ObservableCollection<ChartData>();
}
public void Add(string key, int value)
{
Populations.Add(new ChartData() { dataName = key, dataValue = value });
}
}
public class ChartData
{
public string dataName { get; set; }
public int dataValue { get; set; }
}
然后在主窗口中:
public MainWindow()
{
InitializeComponent();
MainViewModel mvm = new MainViewModel();
mvm.Add("asd", 123);
mvm.Add("sdfs", 133);
mvm.Add("asda", 129);
mvm.Add("asgfgfhd", 23);
test1.DataContext = mvm;
}
在 XAML 中:
<chart:StackedColumnChart x:Name="test1" ChartSubTitle="Population in millions"
ChartTitle="Countries by population" Margin="10,10,0,0" HorizontalAlignment="Left" Width="1573" Height="475" VerticalAlignment="Top">
<chart:StackedColumnChart.Series>
<chart:ChartSeries DisplayMember="dataName"
ItemsSource="{Binding Populations}"
*SeriesTitle="World largest populations"*
ValueMember="dataValue" />
</chart:StackedColumnChart.Series>
</chart:StackedColumnChart>
如何以编程方式设置SeriesTitle值?