当前位置: 首页 > news >正文

WPF livecharts 折线图遮挡数字问题

在WPF里使用livecharts,如果折线图或者柱状图有多个的时候,可能会出现两个数字遮挡问题,这时候要设置DataLabelsTemplate 属性。

如LineSeries设置代码如下:

第一个折线图的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 };

设置LineSeries

Func<double, string> Formatter;
SeriesCollection = new SeriesCollection
{new LineSeries{Title = "",DataLabels=true,//注意设置在这里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,//注意设置在这里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;

具体位置可能要根据你的图表大小调整,主要就是调整

textBlockFactoryA2.SetValue(TextBlock.MarginProperty, new Thickness(0, 0, 0, -40));

这句话。另外字体大小什么的也可以根据需求调整

http://www.lryc.cn/news/186481.html

相关文章:

  • 电力系统数字化升级改造之配电室无人值守
  • 集合Set
  • TCP/IP(二)导论
  • Java之UDP,TCP的详细解析
  • 【总结】kubernates crd client-java 关于自定义资源的增删改查
  • 蓝牙主要知识,一文概览
  • Linux 守护进程
  • 自动驾驶技术的基础知识
  • 解决:yarn 无法加载文件 “C:\Users\XXXXX\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本“ 的问题
  • 【JVM--StringTable字符串常量池】
  • Large Language Models Meet Knowledge Graphs to Answer Factoid Questions
  • blender 之视频渲染(以三维重建path为例)
  • leetcode做题笔记166. 分数到小数
  • Android Studio新建项目缓慢解决方案
  • AmdU (5-azidomethyl-2‘-deoxyuridine)的反应原理|59090-48-1
  • 使用nvm安装多个node版本
  • 基于springboot实现自习室预订系统的设计与实现项目【项目源码+论文说明】分享
  • 淘宝详情API接口
  • 充气膜结构的应用领域
  • 自动拟人对话机器人在客户服务方面起了什么作用?
  • 检验检疫系统(LIS)源码:C# + MVC + SQLserver + Redis
  • tcpdump(一)基础理论知识
  • 一种重要的天然氨基酸L-Homopropargylglycine(HPG)|CAS:942518-19-6
  • uniapp快速入门系列(3)- CSS技巧与布局
  • NCNN:备忘
  • 用Python简单的实现一下六大主流小说平台小说下载(附源码)
  • c++模板库容器list vector map set操作和性能对比
  • windows服务添加 nginx 开机自启
  • 【Redis】redis的特性和使用场景
  • opengauss数据备份(docker中备份)