c# 画散点图——大量点4万个--动态刷新

2024-01-28 15:10

本文主要是介绍c# 画散点图——大量点4万个--动态刷新,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

代码如下,用的devexpress chartcontrol,代码如下:

 public partial class Form1 : Form{public Form1(){InitializeComponent();}int row = 0;//点数int value = 0;//数值Random rd = new Random();//随机值const int nnnn = 34;// 创建一个点图ChartControl pointChart = new ChartControl();DevExpress.XtraCharts.XYDiagram xyDiagram1 = new DevExpress.XtraCharts.XYDiagram();List<Series> ls = new List<Series>();private void addPoint(object source, System.Timers.ElapsedEventArgs e){try{lock(pointChart){BeginInvoke((Action)(() => {if (pointChart.Series.Count > nnnn - 1 && pointChart.Series[0].View.GetType().Equals(typeof(PointSeriesView))){for (int j = 0; j < nnnn; j++){pointChart.Series[j].DataSource = GenerateCluster(rd, 140, 1280, 100, 1240, 1024);}foreach (Series series in pointChart.Series){series.ArgumentDataMember = "Argument";series.ValueDataMembers.AddRange("Value");}}}));}}catch (Exception ex){MessageBox.Show(ex.ToString());}}public static SimpleDataPoint[] GenerateCluster(Random random, int xPlus, int xMinus, int yPlus, int yMinus, int count){SimpleDataPoint[] seriesPoints = new SimpleDataPoint[count];int deltaX = xMinus - xPlus;int deltaY = yMinus - yPlus;int centerX = xMinus / 2 + xPlus / 2;int centerY = yMinus / 2 + yPlus / 2;for (int i = 0; i < count; i++){int half = i / 2 + 1;double ratio = Math.Max(2.1, (double)count / half);int xOffset = (int)(deltaX / ratio);int yOffset = (int)(deltaY / ratio);int delta = xMinus - xOffset - centerX;int rx, ry;do{rx = random.Next(xPlus + xOffset, xMinus - xOffset);ry = random.Next(yPlus + yOffset, yMinus - yOffset);}while (delta * delta < Math.Pow((centerX - rx), 2) + Math.Pow((centerY - ry), 2));seriesPoints[i] = new SimpleDataPoint(rx, ry);}return seriesPoints;}private void Form1_Load(object sender, EventArgs e){for(int i = 0; i< nnnn; i++){string name = "series " + (i+1);// 创建一条曲线Series series1 = new Series(name, ViewType.Point);//设置序列的数字参数比例类型,默认情况下是定性的。series1.ArgumentScaleType = ScaleType.Numerical;//将线条加入到表中//pointChart.Series.Add(series1);ls.Add(series1);//访问该系列的特定于视图类型的选项。PointSeriesView myView1 = (PointSeriesView)series1.View;myView1.PointMarkerOptions.Kind = MarkerKind.Circle;//myView1.PointMarkerOptions.StarPointCount = 5;myView1.PointMarkerOptions.Size = 4;myView1.PointMarkerOptions.BorderColor = Color.FromArgb(i*10);//点的颜色}this.pointChart.SeriesSerializable = ls.ToArray();//创建上下限线条//XYDiagram diagram = (XYDiagram)pointChart.Diagram;//diagram.DefaultPane.BackColor = Color.LemonChiffon;//背景颜色//diagram.AxisY.ConstantLines.Clear();//ConstantLine constantLine1 = new ConstantLine("上限", 30);//constantLine1.Color = Color.Black;//直线颜色//constantLine1.Title.TextColor = Color.Black;//直线文本字体颜色      //diagram.AxisY.ConstantLines.Add(constantLine1);//ConstantLine constantLine2 = new ConstantLine("下限", 20);//constantLine2.Color = Color.Black;//constantLine2.Title.TextColor = Color.Black;//diagram.AxisY.ConstantLines.Add(constantLine2);//隐藏图例(如有必要)。//pointChart.Legend.Visible = true;pointChart.Legend.Visibility = DefaultBoolean.True;pointChart.SeriesTemplate.LabelsVisibility = DefaultBoolean.True;pointChart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Left;pointChart.Legend.AlignmentVertical = LegendAlignmentVertical.Top;pointChart.Legend.Direction = LegendDirection.LeftToRight;this.pointChart.Legend.BackColor = System.Drawing.Color.Transparent;this.pointChart.Legend.Border.Visibility = DevExpress.Utils.DefaultBoolean.False;this.pointChart.BorderOptions.Visibility = DevExpress.Utils.DefaultBoolean.False;this.pointChart.CrosshairOptions.CrosshairLabelMode = DevExpress.XtraCharts.CrosshairLabelMode.ShowForNearestSeries;this.pointChart.CrosshairOptions.HighlightPoints = true;this.pointChart.CrosshairOptions.LinesMode = DevExpress.XtraCharts.CrosshairLinesMode.Auto;this.pointChart.CrosshairOptions.ShowArgumentLabels = true;this.pointChart.CrosshairOptions.ShowCrosshairLabels = true;this.pointChart.CrosshairOptions.ShowValueLabels = true;this.pointChart.CrosshairOptions.ShowGroupHeaders = true;this.pointChart.CrosshairOptions.ShowValueLine = true;//设置Y轴最小值和最大值,即默认情况下Y轴显示的范围AxisRange DIA = (AxisRange)((XYDiagram)pointChart.Diagram).AxisX.Range;DIA.SetMinMaxValues(0, 1024);//将图表添加到界面。pointChart.Dock = DockStyle.Fill;this.Controls.Add(pointChart);//定时器System.Timers.Timer t = new System.Timers.Timer(1000);//实例化Timer类,设置间隔时间为1000毫秒;t.Elapsed += new System.Timers.ElapsedEventHandler(addPoint);//到达时间的时候执行事件;t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;t.Start();//启动}}public class SimpleDataPoint{public double Argument { get; private set; }public double Value { get; private set; }public SimpleDataPoint(double arg, double val){Argument = arg;Value = val;}}

效果图如下:

这篇关于c# 画散点图——大量点4万个--动态刷新的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/654005

相关文章

Java使用Javassist动态生成HelloWorld类

《Java使用Javassist动态生成HelloWorld类》Javassist是一个非常强大的字节码操作和定义库,它允许开发者在运行时创建新的类或者修改现有的类,本文将简单介绍如何使用Javass... 目录1. Javassist简介2. 环境准备3. 动态生成HelloWorld类3.1 创建CtC

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

C#实现一键批量合并PDF文档

《C#实现一键批量合并PDF文档》这篇文章主要为大家详细介绍了如何使用C#实现一键批量合并PDF文档功能,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言效果展示功能实现1、添加文件2、文件分组(书签)3、定义页码范围4、自定义显示5、定义页面尺寸6、PDF批量合并7、其他方法

C#下Newtonsoft.Json的具体使用

《C#下Newtonsoft.Json的具体使用》Newtonsoft.Json是一个非常流行的C#JSON序列化和反序列化库,它可以方便地将C#对象转换为JSON格式,或者将JSON数据解析为C#对... 目录安装 Newtonsoft.json基本用法1. 序列化 C# 对象为 JSON2. 反序列化

C#文件复制异常:"未能找到文件"的解决方案与预防措施

《C#文件复制异常:未能找到文件的解决方案与预防措施》在C#开发中,文件操作是基础中的基础,但有时最基础的File.Copy()方法也会抛出令人困惑的异常,当targetFilePath设置为D:2... 目录一个看似简单的文件操作问题问题重现与错误分析错误代码示例错误信息根本原因分析全面解决方案1. 确保

基于C#实现PDF转图片的详细教程

《基于C#实现PDF转图片的详细教程》在数字化办公场景中,PDF文件的可视化处理需求日益增长,本文将围绕Spire.PDFfor.NET这一工具,详解如何通过C#将PDF转换为JPG、PNG等主流图片... 目录引言一、组件部署二、快速入门:PDF 转图片的核心 C# 代码三、分辨率设置 - 清晰度的决定因

C# LiteDB处理时间序列数据的高性能解决方案

《C#LiteDB处理时间序列数据的高性能解决方案》LiteDB作为.NET生态下的轻量级嵌入式NoSQL数据库,一直是时间序列处理的优选方案,本文将为大家大家简单介绍一下LiteDB处理时间序列数... 目录为什么选择LiteDB处理时间序列数据第一章:LiteDB时间序列数据模型设计1.1 核心设计原则

C#高效实现Word文档内容查找与替换的6种方法

《C#高效实现Word文档内容查找与替换的6种方法》在日常文档处理工作中,尤其是面对大型Word文档时,手动查找、替换文本往往既耗时又容易出错,本文整理了C#查找与替换Word内容的6种方法,大家可以... 目录环境准备方法一:查找文本并替换为新文本方法二:使用正则表达式查找并替换文本方法三:将文本替换为图

C#使用Spire.XLS快速生成多表格Excel文件

《C#使用Spire.XLS快速生成多表格Excel文件》在日常开发中,我们经常需要将业务数据导出为结构清晰的Excel文件,本文将手把手教你使用Spire.XLS这个强大的.NET组件,只需几行C#... 目录一、Spire.XLS核心优势清单1.1 性能碾压:从3秒到0.5秒的质变1.2 批量操作的优雅

C#和Unity中的中介者模式使用方式

《C#和Unity中的中介者模式使用方式》中介者模式通过中介者封装对象交互,降低耦合度,集中控制逻辑,适用于复杂系统组件交互场景,C#中可用事件、委托或MediatR实现,提升可维护性与灵活性... 目录C#中的中介者模式详解一、中介者模式的基本概念1. 定义2. 组成要素3. 模式结构二、中介者模式的特点