WPF工具包图表 - 自定义工具提示 - 显示复杂的相关值

时间:2013-04-09 10:30:16

标签: wpf templates charts tooltip toolkit

我有以下图表:

<cht:Chart ...>
    <cht:Chart.Series>
        <cht:LineSeries Name="LineSeries" Title="a"
            DependentValueBinding="{Binding Path=Value}"
            IndependentValueBinding="{Binding Path=Key}"
            ItemsSource="{Binding Path=SourceCollection}"
            IsSelectionEnabled="True"
            DataPointStyle="{DynamicResource SmallPointStyle}">
       </cht:LineSeries>
   </cht:Chart.Series>
</cht:Chart>

DataPointStyle:

<Style TargetType="cht:LineDataPoint"> 
    <Setter Property="Width" Value="2" />
    <Setter Property="Height" Value="2" />
    <Setter Property="DependentValueStringFormat" Value="{}{0:0.00}"/>
</Style>
<Style x:Key="SmallPointStyle" TargetType="cht:LineDataPoint" BasedOn="{StaticResource {x:Type cht:LineDataPoint}}">
    <Setter Property="BorderBrush" Value="Orange"/>
    <Setter Property="Background" Value="Orange"/>
</Style>

源集合是KeyValuePair的列表。 该应用程序运行正常。

我遇到了一个问题因为我想使用KeyValuePair的集合&gt;其中doubleA是提取的数据,doubleB是doubleA的标准化值,基于范围。所以我需要将LineSeries更改为:

<cht:Chart ...>
    <cht:Chart.Series>
        <cht:LineSeries Name="LineSeries" Title="a"
        DependentValueBinding="{Binding Path=Value.Value}"
        IndependentValueBinding="{Binding Path=Key}"
        ItemsSource="{Binding Path=SourceCollection}"
        IsSelectionEnabled="True"
        DataPointStyle="{DynamicResource SmallPointStyle}">
       </cht:LineSeries>
    </cht:Chart.Series>
</cht:Chart>

它按预期工作,但我需要在工具提示中显示实际值(Value.Key),而不是DependentValue。无论如何要做到这一点?

1 个答案:

答案 0 :(得分:0)

有关一种可能的解决方案,请参阅此blog post

您找到必须覆盖here的LineSeries数据点样式。 但是,请记住,当您覆盖模板时,您将不再获得任何随机颜色。

祝你好运!

相关问题