silverlight中C1Chart Bar图添加标签,显示位置不是想要的
如下图是我做的-->
现在想要数字标签变成这样(图中红框圈出来)-->
我的代码如下:
前台:
- <local:ChartPointConverter x:Key="pc"/>
- <DataTemplate x:Key="tip">
- <TextBlock FontSize="10" Margin="1,1,1,20" Foreground="Black" Text="{Binding Converter={StaticResource pc}}" />
- </DataTemplate>
复制代码 ChartPointConverter:
- public class ChartPointConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- DataPoint point = value as DataPoint;
- if (point != null)
- {
- try
- {
- object retStr = "";
- retStr = point.Value == 0 ? "" : point.Value.ToString();
- return retStr;
- }
- catch (FormatException)
- {
- }
- }
- return value;
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
复制代码 后台xaml.cs代码:
- ///设置Chart图标签
- DataTemplate Tip = (DataTemplate)Resources["tip"];
- chart.Data.Children[0].PointLabelTemplate = Tip;
- chart.Data.Children[1].PointLabelTemplate = Tip;
- chart.Data.Children[2].PointLabelTemplate = Tip;
复制代码 求教
|