XAML代码<Pagex:Class="CStackLineChat.MainPage"...xmlns:charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"mc:Ignorable="d"><Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="50" > <charting:Chart x:Name="MyChart" Title="Stacked column Chart"> <charting:StackedLineSeries> <charting:StackedLineSeries.SeriesDefinitions> <charting:SeriesDefinition DependentValuePath="Amount" IndependentValuePath="Name" IsTapEnabled="True" Title="Doodad" /> <charting:SeriesDefinition Title="Stan2" DependentValuePath="Amount" IndependentValuePath="Name"/> </charting:StackedLineSeries.SeriesDefinitions> </charting:StackedLineSeries> </charting:Chart></Grid></Page>后面的代码public sealed partial class MainPage : Page{ private Random _random = new Random(); List<NameValueItem> Records = new List<NameValueItem>(); List<NameValueItem> Records2 = new List<NameValueItem>(); public MainPage() { this.InitializeComponent(); for (int i = 0; i < 5; i++) { Records.Add(new NameValueItem { Name = "Name" + i, Amount = _random.Next(10, 100) }); Records2.Add(new NameValueItem { Name = "Name" + i, Amount = _random.Next(10, 100) }); } this.RunIfSelected(this.MyChart, () => ((StackedLineSeries)this.MyChart.Series[0]).SeriesDefinitions[0].ItemsSource = Records); this.RunIfSelected(this.MyChart, () => ((StackedLineSeries)this.MyChart.Series[0]).SeriesDefinitions[1].ItemsSource = Records2); } private void RunIfSelected(UIElement element, Action action) { action.Invoke(); }}public class NameValueItem{ public string Name { get; set; } public int Amount { get; set; }}结果此外,通过在我这一边进行测试,似乎DependentValuePath和IndependentValuePath属性不能直接绑定到您的方案中.使用此软件包的最佳方法是遵循官方示例. 此处是图表示例. I am trying to use WinRTXamlToolkit.Controls.DataVisualization.UWPtrying to draw any of the stacked charts like this:But only this comes out:Please help me, I have to use stacked series but the framework doesn't act as it should be.. 解决方案 Since I don't know how you define the code behind, I just provide the sample code as follows which can create a StackedLineSeries chart successfully.XAML Code<Pagex:Class="CStackLineChat.MainPage"...xmlns:charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"mc:Ignorable="d"><Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Padding="50" > <charting:Chart x:Name="MyChart" Title="Stacked column Chart"> <charting:StackedLineSeries> <charting:StackedLineSeries.SeriesDefinitions> <charting:SeriesDefinition DependentValuePath="Amount" IndependentValuePath="Name" IsTapEnabled="True" Title="Doodad" /> <charting:SeriesDefinition Title="Stan2" DependentValuePath="Amount" IndependentValuePath="Name"/> </charting:StackedLineSeries.SeriesDefinitions> </charting:StackedLineSeries> </charting:Chart></Grid></Page>Code behindpublic sealed partial class MainPage : Page{ private Random _random = new Random(); List<NameValueItem> Records = new List<NameValueItem>(); List<NameValueItem> Records2 = new List<NameValueItem>(); public MainPage() { this.InitializeComponent(); for (int i = 0; i < 5; i++) { Records.Add(new NameValueItem { Name = "Name" + i, Amount = _random.Next(10, 100) }); Records2.Add(new NameValueItem { Name = "Name" + i, Amount = _random.Next(10, 100) }); } this.RunIfSelected(this.MyChart, () => ((StackedLineSeries)this.MyChart.Series[0]).SeriesDefinitions[0].ItemsSource = Records); this.RunIfSelected(this.MyChart, () => ((StackedLineSeries)this.MyChart.Series[0]).SeriesDefinitions[1].ItemsSource = Records2); } private void RunIfSelected(UIElement element, Action action) { action.Invoke(); }}public class NameValueItem{ public string Name { get; set; } public int Amount { get; set; }}And the resultAdditionally, by testing on my side, it seems like DependentValuePath and IndependentValuePath properties can not directly binding in your scenario. The best way to use this package is to follow the official sample. Here is the chart sample. 这篇关于UWP StackedLineSeries不显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 00:40