UWP StackedLineSeries不显示值

时间:2016-11-15 12:28:36

标签: binding uwp winrt-xaml data-visualization datavisualization.toolkit

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

尝试绘制任何堆叠的图表,如下所示:

enter image description here

但只有这一点出来了:

enter image description here

请帮助我,我必须使用堆叠系列,但框架不能正常运行..

1 个答案:

答案 0 :(得分:1)

由于我不知道如何定义后面的代码,我只是提供如下示例代码,可以成功创建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; }
}

结果 enter image description here

此外,通过我的测试,似乎DependentValuePathIndependentValuePath属性无法在您的方案中直接绑定。使用此程序包的最佳方法是遵循official sampleHere是图表示例。