C#-WPF-控件-CartesianChart图表-线性3(LineSeries)-MVVM模式(封装数据绑定类)
知识点1. 数据绑定数据绑定类 与 图形操作在同一个类中2. X轴上显示点数主类 中3. 添加随机值在图表中 值针对Y轴值4. 清空图表5. 图标titel显示实例图表控件绑定 SeriesCollectionA Utils_ChartA.cs中lvc:CartesianChart x:NameLiveChartsA Margin10,146,185,51 Series{Binding SeriesCollectionA} Background#FFF8FCFD LegendLocationTop /lvc:CartesianChart提示框绑定 MsgTips Utils_ChartA.cs中Label Grid.Row2 Grid.Column0 FontSize12 Background#22FF0000 Content{Binding MsgTips} /Utils_ChartA.cs(数据绑定类 与 图形操作在同一个类中)using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Text; using System.Windows.Media; using LiveCharts; using LiveCharts.Wpf; namespace Wpf_Math.MyUC_TestChart { public class Utils_ChartA : INotifyPropertyChanged { private string _msgTips; private SeriesCollection _seriesCollectionA; public Utils_ChartA() { // 在构造函数中初始化 _seriesCollectionA new SeriesCollection(); } public string MsgTips { get _msgTips; set { _msgTips value; OnPropertyChanged(); } } public SeriesCollection SeriesCollectionA { get _seriesCollectionA; set { if (_seriesCollectionA ! value) { _seriesCollectionA value; OnPropertyChanged(); } } } public void InitializeLiveCharts1(int XPonitLength) { if (XPonitLength 0) XPonitLength 100; LineSeries myLineseries new LineSeries() //实例化一条折线图 { Title M485-----电压测试图, //设置折线的标题 StrokeThickness 1, // 设置折线粗细 LineSmoothness 1, //折线图直线形式 0 or 1 PointGeometry null, //折线图的无点样式 Stroke Brushes.Red, // 红色线条 Values new ChartValuesdouble(new Double[XPonitLength]) //添加折线图的数据(X轴划分点数) }; SeriesCollectionA.Add(myLineseries); } public void addData(double n) { //通过Dispatcher在工作线程中更新窗体的UI元素 Debug.Write(n n \r\n); SeriesCollectionA[0].Values.Add(n); SeriesCollectionA[0].Values.RemoveAt(0); } public void Clear(CartesianChart Chart) { Chart.Series.Clear(); //清空数据 InitializeLiveCharts1(0); //重复新初始化 } public event PropertyChangedEventHandler? PropertyChanged; protected void OnPropertyChanged([CallerMemberName] string name null) PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } }主操作界面using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using LiveCharts; using LiveCharts.Wpf; namespace Wpf_Math.MyUC_TestChart { public partial class UC_ChartA : UserControl { int i; Utils_ChartA ChartA new Utils_ChartA(); public UC_ChartA() { InitializeComponent(); this.DataContext ChartA; ChartA.MsgTips 提示; ChartA.InitializeLiveCharts1(0); } private void Button_Click(object sender, RoutedEventArgs e) { Button button (Button)sender; ChartA.MsgTips 你点击了-- button.Content i; //Debug.Write(你点击了--btn_calulate\\r\n) switch (button.Name) { case btn_addA: { ChartA.addData(new Random().Next(0, 30)); break; } case btn_addB: { ChartA.addData(new Random().Next(80, 99)); break; } case btn_clear:{ ChartA.Clear(LiveChartsA);break;} default: break; } } } }将持续更新

相关新闻

Python操作MySQL数据库进阶指南:连接池与事务管理

Python操作MySQL数据库进阶指南:连接池与事务管理

1. Python操作MySQL数据库全景指南作为数据驱动应用的核心组件,数据库操作一直是Python开发者必须掌握的硬技能。MySQL作为最流行的开源关系型数据库,与Python的配合堪称黄金组合。但很多开发者停留在基础CRUD阶段,对连接池、事务管理等进阶用…

2026/7/28 20:04:41 阅读更多
ElasticSearch-bulk批量操作增删改查(python实现)

ElasticSearch-bulk批量操作增删改查(python实现)

bulk有哪些类型的操作可以执行呢? # 1.bulk的语法是怎样的呢? 每一个操作要两个json串,语法如下: {"action": {"metadata"}} {"data"} # 2.bulk的操作有以下几种 (1)delete:删除一个文…

2026/7/28 20:04:41 阅读更多
FPGA实战(58):10G Ethernet XGMII PHY层 接口设计与仿真验证

FPGA实战(58):10G Ethernet XGMII PHY层 接口设计与仿真验证

引言 随着数据中心与高速互联场景对带宽需求的持续增长,10 Gigabit Ethernet(10GbE)已成为各类 FPGA 平台的标准高速接口方案。IEEE 802.3ae 定义的 10GBASE-R 物理层采用 64B/66B 编码,通过 XGMII(10 Gigabit Media Independent Interface)总线与 MAC 层交互——数据通…

2026/7/29 9:06:11 阅读更多
AI如何提升学术写作效率与质量

AI如何提升学术写作效率与质量

1. 当AI遇上学术写作:一场生产力革命的开端 十年前我完成第一部学术专著时,整整耗费了两年半的周末和假期。如今看着团队里的年轻学者用AI工具三个月就能完成同等质量的初稿,这种代际差异让我深刻意识到:学术写作正在经历古腾堡印…

2026/7/29 9:06:11 阅读更多
iOS持续集成中证书管理的最佳实践与解决方案

iOS持续集成中证书管理的最佳实践与解决方案

1. iOS持续集成中的证书管理痛点在iOS应用的CI/CD流程中,证书和配置文件的管理一直是开发者最头疼的问题之一。不同于Android开发可以直接使用调试密钥,苹果的生态要求每个应用都必须使用有效的证书签名才能安装到设备上。这就导致在Jenkins自动化构建时…

2026/7/29 9:06:11 阅读更多
LARA-R6401与PIC18LF45K42的低功耗物联网设计实践

LARA-R6401与PIC18LF45K42的低功耗物联网设计实践

1. LARA-R6401与PIC18LF45K42的硬件协同设计在物联网边缘计算领域,LARA-R6401 LTE Cat 1模块与PIC18LF45K42微控制器的组合正在开创低功耗广域连接的新范式。这个组合最吸引人的特点是:LARA-R6401提供了仅24x26mm的紧凑封装中集成了全球多频段LTE连接能力…

2026/7/29 8:56:11 阅读更多