UWP StackedLineSeries 不显示值

UWP StackedLineSeries doesn't show values

我正在尝试使用 WinRTXamlToolkit.Controls.DataVisualization.UWP

尝试像这样绘制任何堆叠图表:

但是只有这个出来了:

请帮帮我,我必须使用堆叠系列,但框架没有发挥应有的作用..

因为我不知道你后面的代码是怎么定义的,所以我只提供示例代码如下,可以成功创建StackedLineSeries图表。

XAML代码

<Page
x: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; }
}

结果

此外,通过我这边的测试,DependentValuePathIndependentValuePath 属性似乎无法直接绑定到您的场景中。使用此包的最佳方法是遵循 official sample. Here 图表示例。