C1Chart Bar图添加标签位置不对
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.PointLabelTemplate = Tip;
chart.Data.Children.PointLabelTemplate = Tip;
chart.Data.Children.PointLabelTemplate = Tip;求教
本帖最后由 Richard.Ma 于 2019-9-30 11:19 编辑
帮您验证了一下,可以用下面的代码,关键代码是c1chart:PlotElement.LabelAlignment="MiddleRight"
<DataTemplate x:Key="lbl">
<Grid c1chart:PlotElement.LabelAlignment="MiddleRight">
<TextBlock FontSize="10" Margin="-40 5 5 5" Foreground="DarkRed" Text="{Binding ConverterParameter=Value: \{#Value\}, Converter={StaticResource fc}}" />
</Grid>
</DataTemplate>
可以重现您的问题,这个需要验证一下,明天早上给您反馈结果
页:
[1]