图片地址:https://blog.csdn.net/qq_33459369/article/details/80060196;(盗图)

接下来是封装的代码

#region 动态折线图
public LineChartHelper(ChartControl chart)
{
LineSeriesView lineSeriesView = new LineSeriesView();
chart.SeriesTemplate.View = lineSeriesView;
//Legend的位置
chart.Legend.AlignmentHorizontal = DevExpress.XtraCharts.LegendAlignmentHorizontal.Left;
chart.Legend.AlignmentVertical = DevExpress.XtraCharts.LegendAlignmentVertical.TopOutside;
chart.Legend.Direction = DevExpress.XtraCharts.LegendDirection.RightToLeft;
//x轴为时间轴
XYDiagram diagram = (XYDiagram)chart.Diagram;
diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Millisecond;
diagram.AxisX.DateTimeScaleOptions.ScaleMode = ScaleMode.Continuous;
} public Series[] CreateSeries(ChartControl chart, List<string> names)
{
chart.Series.Clear();//清除Series
int num = names.Count();
Series[] series = new Series[num];
for (int i = ; i < num; i++)
{
series[i] = CreateSeries(names[i], ViewType.Line);
}
return series;
}
/// <summary>
/// 创建折线
/// </summary>
private Series CreateSeries(string caption, ViewType viewType)
{
Series series = new Series(caption, viewType);
//必须设置ArgumentScaleType的类型,否则显示会转换为日期格式,导致不是希望的格式显示
//也就是说,显示字符串的参数,必须设置类型为ScaleType.Qualitative
series.ArgumentScaleType = ScaleType.Auto;
series.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//显示标注标签
//回归线
LineSeriesView lineSeriesView = new LineSeriesView();
RegressionLine regressionLine = new RegressionLine();
regressionLine.Name = caption + "";
lineSeriesView.Indicators.AddRange(new DevExpress.XtraCharts.Indicator[] { regressionLine });
series.View = lineSeriesView;
return series;
}
/// <summary>
/// 移除不在视图显示的Points数据
/// </summary>
/// <param name="series">曲线</param>
/// <param name="minDate">时间线</param>
public void RemovePoint(DateTime minDate, Series[] series)
{
int pointsToRemoveCount = ;//曲线节点数据
foreach (SeriesPoint point in series[].Points)
{
if (point.DateTimeArgument < minDate)
pointsToRemoveCount++;
}
if (pointsToRemoveCount < series[].Points.Count)
{
pointsToRemoveCount--;
}
if (pointsToRemoveCount > )
{
for (int i = ; i < series.Count(); i++)
{
series[i].Points.RemoveRange(, pointsToRemoveCount);
}
}
}
/// <summary>
/// 添加数据到曲线节点
/// </summary>
public void AddPoints(Series series, DateTime argument, double value)
{
if (series.View is LineSeriesView)
{
series.Points.Add(new SeriesPoint(argument, value));
}
}
/// <summary>
/// 设置x轴数据
/// </summary>
public void SetX(ChartControl chart, DateTime minDate, DateTime argument)
{
XYDiagram diagram = (XYDiagram)chart.Diagram;
if (diagram != null && (diagram.AxisX.DateTimeScaleOptions.MeasureUnit == DateTimeMeasureUnit.Millisecond || diagram.AxisX.DateTimeScaleOptions.ScaleMode == ScaleMode.Continuous))
{
diagram.AxisX.WholeRange.SetMinMaxValues(minDate, argument);
}
}
/// <summary>
/// 获取曲线的回归线
/// </summary>
public RegressionLine GetRegressionLine(Series series)
{
if (series != null)
{
SwiftPlotSeriesView swiftPlotView = series.View as SwiftPlotSeriesView;
if (swiftPlotView != null)
{
Console.Write(swiftPlotView.Indicators);
foreach (Indicator indicator in swiftPlotView.Indicators)
{
RegressionLine regressionLine = indicator as RegressionLine;
if (regressionLine != null)
return regressionLine;
}
}
}
return null;
}
#endregion

调用代码

        private readonly Random random = new Random();
private Series[] _series;
private LineChartHelper _lineChartHelper;
private int _num = ; public frmRealtimeLineChart()
{
InitializeComponent(); } private void frmRealtimeLineChart_Load(object sender, EventArgs e)
{
Init();
} private void Init()
{
_lineChartHelper = new LineChartHelper(chart);
List<string> names = new List<string>() { "曲线一", "折线二", "数字三" };
_series = _lineChartHelper.CreateSeries(chart, names);
_num = names.Count();
chart.SeriesSerializable = _series; XYDiagram diagram = (XYDiagram)chart.Diagram;
diagram.AxisX.GridLines.MinorVisible = true;
diagram.AxisX.GridLines.Visible = true;
diagram.AxisX.Label.TextPattern = "@{A:HH:mm:ss}";
diagram.AxisX.Title.Font = new System.Drawing.Font("Tahoma", 9F);
diagram.AxisX.Title.Text = @"时间(分)";
diagram.AxisX.Title.Visible = true;
diagram.AxisX.VisibleInPanesSerializable = "-1"; diagram.AxisX.WholeRange.Auto = true;
diagram.AxisX.WholeRange.SideMarginsValue = ;
diagram.AxisX.Interlaced = true;
diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false; diagram.AxisY.Title.Font = new System.Drawing.Font("Tahoma", 9F);
diagram.AxisY.Title.Text = @"随机数";
diagram.AxisY.Title.Visible = true;
diagram.AxisY.VisibleInPanesSerializable = "-1";
} private void timer_Tick(object sender, EventArgs e)
{
RealtimeChart();
} private void RealtimeChart()
{
try
{
DateTime argument = DateTime.Now;//x轴
for (int i = ; i < _num; i++)
{
_lineChartHelper.AddPoints(_series[i], argument, CalculateNextValue());
}
DateTime minDate = argument.AddSeconds(-TimeInterval);//x轴时间曲度
_lineChartHelper.RemovePoint(minDate, _series);
_lineChartHelper.SetX(chart, minDate, argument);
}
catch (Exception ex)
{
Console.Write(ex);
}
} /// <summary>
/// 随机数
/// </summary>
private double CalculateNextValue()
{
return Math.Round(random.NextDouble() * 100.0);
} /// <summary>
/// 间隔时间
/// </summary>
private int TimeInterval { get { return Convert.ToInt32(spnTimeInterval.EditValue); } }

直接拖入chart,选择折线图,效果如下:

dev linechart动态加载数据(像股票一样的波动)的更多相关文章

  1. AppCan学习笔记----关闭页面listview动态加载数据

    AppCan页面关闭 AppCan 的页面是由两个HTML组成,如果要完全关闭的话需要在主HTML eg.index.html中关闭,关闭方法:appcan.window.close(-1); 管道 ...

  2. [JS前端开发] js/jquery控制页面动态加载数据 滑动滚动条自动加载事件

    页面滚动动态加载数据,页面下拉自动加载内容 相信很多人都见过瀑布流图片布局,那些图片是动态加载出来的,效果很好,对服务器的压力相对来说也小了很多 有手机的相信都见过这样的效果:进入qq空间,向下拉动空 ...

  3. 微信小程序(五) 利用模板动态加载数据

    利用模板动态加载数据,其实是对上一节静态数据替换成动态数据:

  4. mui 动态加载数据出现的问题处理 (silder轮播组件 indexedList索引列表 下拉刷新不能继续加载数据)

    mui-slider 问题:动态给mui的图片轮播添加图片,轮播不滚动. 解决:最后把滚动轮播图片的mui(".mui-slider").slider({interval: 300 ...

  5. ASP.NET MVC动态加载数据

    ASP.NET MVC动态加载数据,一般的做法是使用$.each方法来循环产生tabel: 你可以在html时先写下非动态的部分:  Source Code 上图中,有一行代码: <tbody ...

  6. js实现滚动条来动态加载数据

    主要angular2+es6 data:Array<any> //展示的数据 allData:Array<any> //全部的数据 size:number = 10 //每次动 ...

  7. js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的

    js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的 相信很多人都见过瀑布流图片布局,那些图片是动态加载出来的,效果很好,对服务器的压力相对来说也小了很多 有手机的相信都见过这样 ...

  8. js动态加载数据并合并单元格

    js动态加载数据合并单元格, 代码如下所示,可复制直接运行: <!DOCTYPE HTML> <html lang="en-US"> <head> ...

  9. 爬虫--selenuim和phantonJs处理网页动态加载数据的爬取

    1.谷歌浏览器的使用 下载谷歌浏览器 安装谷歌访问助手 终于用上谷歌浏览器了.....激动 问题:处理页面动态加载数据的爬取 -1.selenium -2.phantomJs 1.selenium 二 ...

随机推荐

  1. Python JSON dump ,load,dumps,loads

    JSON是一种轻量级的数据交换格式. json.dump() 将Python数据格式序列化为json数据格式(字符串)并储存在json文件之中. json.load()将Jons数据(字符串)反序列化 ...

  2. kafka 基本原理简介

    Kafka是啥?用Kafka官方的话来说就是: Kafka is used for building real-time data pipelines and streaming apps. It i ...

  3. LeetCode 搜索旋转排序数组

    假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这个目标值, ...

  4. js常用正则(2)

    res(a, b, str) { //数字加英文 let re = `\^\\w{${a},${b}}\$` let reg = new RegExp(re); let status = !reg.t ...

  5. 阶段5 3.微服务项目【学成在线】_day05 消息中间件RabbitMQ_15.RabbitMQ研究-与springboot整合-声明交换机和队列

    复制topic的代码 把常量都设置成public方便其他的类引用 ExchangeBuilder里面有4个方法分别对应四个交换机. 声明Email和短信的队列 队列绑定交换机 所以需要把Bean注入到 ...

  6. jackson将json数组转成List、普通数组。

    package com.mkyong; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jacks ...

  7. k8s install kubeadm网络原因访问不了谷哥and gpg: no valid OpenPGP data found. 解决办法

    gpg: no valid OpenPGP data found. 解决办法 待做.................................... 卡助在这curl -s https://pa ...

  8. 利用工具破解HTTP身份验证的多种方法

    https://www.hackingarticles.in/multiple-ways-to-exploiting-http-authentication/ 1)场景 利用Apache配置HTTP验 ...

  9. 微信小程序的场景值scene

    根据微信小程序返回给我们的场景值,我们可以根据不同的场景做出不同的处理,更加方便我们对使用场景的划分 当前支持的场景值有: :发现栏小程序主入口,“最近使用”列表(基础库2..4版本起将包含“我的小程 ...

  10. 我是如何提高工作效率的-工具篇(一)-Clover

    痛点: 还在为资源管理器窗口切来切去烦恼吗? 效果图: 实现工具:Clover 放个链接 链接:https://pan.baidu.com/s/1UiUQZtE99fMNDe1f2gOnlg   提取 ...