【问题标题】:UWP StackedLineSeries doesn't show valuesUWP StackedLineSeries 不显示值
【发布时间】:2017-03-29 08:05:45
【问题描述】:

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

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

但只有这个出来:

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

【问题讨论】:

  • 您是否在 Visual Studio 的“输出”选项卡中检查了绑定错误?
  • 是的,没有绑定错误..
  • 您是否尝试过将绑定模式更改为 OneWay? {绑定记录,模式=OneWay}

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


【解决方案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; }
}

结果

此外,通过我这边的测试,DependentValuePathIndependentValuePath 属性似乎无法直接绑定到您的场景中。使用这个包的最好方法是关注official sampleHere 是图表示例。

【讨论】:

  • 谢谢!它以这种方式工作(使用后面的代码),但将在 MVVM 模式中使用它,因此将其绑定到 ViewModel 中的属性。正如我在图表示例中看到的那样,开发人员不会在堆叠图表中使用绑定,仅在简单的......也许是因为它仍然不受支持?顺便说一句,感谢您的帮助,我将深入检查此示例。
  • @Farkanyal 实际上我无法判断它是否通过官方文档支持很差。作为我这边的测试,绑定是行不通的。请尝试对DependentValueBinding 进行更多测试。对于新问题,您可以打开新线程寻求帮助。谢谢。
猜你喜欢
  • 2020-02-05
  • 2017-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
  • 2019-03-19
  • 2020-08-27
相关资源
最近更新 更多