在WPF里使用livecharts,如果折線圖或者柱狀圖有多個的時候,可能會出現(xiàn)兩個數(shù)字遮擋問題,這時候要設(shè)置DataLabelsTemplate 屬性。
如LineSeries設(shè)置代碼如下:
第一個折線圖的DataLabelsTemplate
var stackPanelFactory = new FrameworkElementFactory(typeof(StackPanel));
stackPanelFactory.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
var textBlockFactoryA = new FrameworkElementFactory(typeof(TextBlock));
textBlockFactoryA.SetValue(TextElement.ForegroundProperty, new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#5BABEF")));
textBlockFactoryA.SetBinding(TextBlock.TextProperty, new Binding("FormattedText"));
textBlockFactoryA.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 0, -8));
stackPanelFactory.AppendChild(textBlockFactoryA);
var dataTemplate = new DataTemplate() { VisualTree = stackPanelFactory };
第二個折線圖的DataLabelsTemplate
var stackPanelFactory2 = new FrameworkElementFactory(typeof(StackPanel));
stackPanelFactory2.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
var textBlockFactoryA2 = new FrameworkElementFactory(typeof(TextBlock));
textBlockFactoryA2.SetValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.White));
textBlockFactoryA2.SetBinding(TextBlock.TextProperty, new Binding("FormattedText"));
textBlockFactoryA2.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 0, -40));
stackPanelFactory2.AppendChild(textBlockFactoryA2);
var dataTemplate2 = new DataTemplate() { VisualTree = stackPanelFactory2 };
設(shè)置LineSeries
Func<double, string> Formatter;
SeriesCollection = new SeriesCollection
{
new LineSeries
{
Title = "",
DataLabels=true,
//注意設(shè)置在這里
DataLabelsTemplate= dataTemplate,
Values = inValueList,
Stroke=new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#5BABEF")),
Foreground= new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#5BABEF")),
FontSize=26,
},
new LineSeries
{
Title="",
DataLabels=true,
//注意設(shè)置在這里
DataLabelsTemplate= dataTemplate2,
Values= outValueList,
Stroke =new SolidColorBrush(Colors.White),
Foreground= new SolidColorBrush(Colors.White),
FontSize=26,
},
};
Formatter = value => value.ToString("N");
lvcWeekLabel.Labels = Labels;
lvcWeekLabel.LabelFormatter = Formatter;
lvcWeek.Series = SeriesCollection;
具體位置可能要根據(jù)你的圖表大小調(diào)整,主要就是調(diào)整
textBlockFactoryA2.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 0, -40));文章來源:http://www.zghlxwxcb.cn/news/detail-726198.html
這句話。另外字體大小什么的也可以根據(jù)需求調(diào)整文章來源地址http://www.zghlxwxcb.cn/news/detail-726198.html
到了這里,關(guān)于WPF livecharts 折線圖遮擋數(shù)字問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!