【发布时间】:2013-07-11 13:39:46
【问题描述】:
回答
感谢 Filip,我终于找到了设置颜色的方法。我只需要在DataPointStyle 中添加Background 属性。我在这里发布我的答案。还找到了如何修改默认工具提示的方法。
Showing lines with different colors on a Silverlight Toolkit’s LineChart?
Using a custom ToolTip in Silverlight charting
<charting:LineSeries.DataPointStyle>
<Style TargetType="charting:LineDataPoint">
<Setter Property="Width" Value="17" />
<Setter Property="Height" Value="17" />
<Setter Property="Background" Value="Lime"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:LineDataPoint">
<Grid>
<ToolTipService.ToolTip>
<ContentControl Content="{Binding Value,Converter={StaticResource MyConv},ConverterParameter=TEST}"/>
</ToolTipService.ToolTip>
<Ellipse Fill="Lime" Stroke="Lime" StrokeThickness="3" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</charting:LineSeries.DataPointStyle>
问题 1
我正在一个图表中创建多个折线图系列。现在 WinRT XAML Toolkit 以随机方式为每个系列分配颜色。我正在为数据点使用自定义样式,所以当我使用自定义样式时,颜色的随机性会消失。那么如何设置或获取系列的随机颜色?如果我可以得到颜色,那么我可以在数据点中使用该颜色,如果我可以设置颜色,那么我将自己生成随机颜色。
问题 2
此外,当将鼠标悬停在数据点上时,工具提示会显示相关值,但我想显示更多详细信息如何实现?
这是我的自定义样式代码。
<charting:Chart x:Name="LineChart" Title="Line Chart" Margin="70,0">
<charting:LineSeries
Title="Population 1"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True">
<charting:LineSeries.DataPointStyle>
<Style TargetType="charting:LineDataPoint">
<Setter Property="Width" Value="17" />
<Setter Property="Height" Value="17" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:LineDataPoint">
<Ellipse Fill="Green" Stroke="Green" StrokeThickness="3" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</charting:LineSeries.DataPointStyle>
</charting:LineSeries>
<charting:LineSeries
Title="Population 2"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True" Foreground="Blue">
<charting:LineSeries.DataPointStyle>
<Style TargetType="charting:LineDataPoint">
<Setter Property="Width" Value="17" />
<Setter Property="Height" Value="17" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:LineDataPoint">
<Ellipse Fill="Red" Stroke="Red" StrokeThickness="3" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</charting:LineSeries.DataPointStyle>
</charting:LineSeries>
</charting:Chart>
随机颜色的图表(无自定义数据点样式)
没有随机颜色的图表(使用自定义数据点样式)[您可以看到两条线都是黄色的]
【问题讨论】:
标签: xaml windows-8 charts windows-runtime winrt-xaml-toolkit