網(wǎng)站首頁 編程語言 正文
C#中使用DevExpress中的ChartControl實(shí)現(xiàn)極坐標(biāo)圖的案例詳解_C#教程
作者:CodingPioneer ? 更新時(shí)間: 2022-04-25 編程語言背景
在工控軟件的開發(fā)中很多業(yè)務(wù)場(chǎng)景就是使用圖表控件展示設(shè)備和工藝參數(shù)。如下圖案例:
實(shí)現(xiàn)思路
通常簡(jiǎn)單的做法是使用圖表控件實(shí)現(xiàn),常用的圖表控件有開源的ZedGraph,還有付費(fèi)的TeeChart和DevExpress。常規(guī)的曲線圖、柱狀圖、餅圖的實(shí)現(xiàn),三個(gè)控件都可以很好的實(shí)現(xiàn),建議使用開源的ZedGraph。但是在實(shí)現(xiàn)雷達(dá)圖、極坐標(biāo)圖等特定圖表時(shí)ZedGraph就不能支持,TeeChart用起來也不是那么完美,對(duì)比后發(fā)現(xiàn)DevExpress的ChartControl實(shí)現(xiàn)還是不錯(cuò)的。
參考代碼
本案例是使用的是DevExpress 18.1.3版本,之前在14版本上也試過,但是有一個(gè)弊端就是實(shí)現(xiàn)極坐標(biāo)圖的時(shí)候,第一個(gè)點(diǎn)和最后一個(gè)點(diǎn)總是自動(dòng)多一條閉合線,會(huì)形成一個(gè)閉合的多邊形,因此升級(jí)了一下版本。在DevExpress中雷達(dá)圖和極坐標(biāo)圖使用的是父子類的關(guān)系,很多屬性一致,為了可以自己定義圓盤上的刻度范圍,這是采用雷達(dá)圖實(shí)現(xiàn)自定義的極坐標(biāo)圖。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using DevExpress.XtraCharts; namespace WinTest { public partial class Form1 : Form { private Stopwatch sw = new Stopwatch(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { sw.Restart(); int fontSize = 9; //字號(hào) int count = 1; //曲線數(shù)量 int points = 8; //每條曲線的點(diǎn)數(shù) int angleMaxValue = 24; //角度最大值 int maxShowPints = 30; //最大顯示的點(diǎn)數(shù) for (int i = 0; i < this.Controls.Count; i++) { if (this.Controls[i] is ChartControl) { this.Controls.RemoveAt(i); break; } } // Create a new chart. ChartControl RadarLineChart = new ChartControl(); // Add a radar series to it. Series[] seriesArr = new Series[count]; List[] pintValuesList = new List [count]; for (int i = 0; i < seriesArr.Length; i++) { pintValuesList[i] = new List (); seriesArr[i] = new Series("Series " + i, ViewType.RadarLine); //使用雷達(dá)折線圖實(shí)例化Series RadarLineSeriesView radLineSeriesView = (seriesArr[i].View as RadarLineSeriesView); radLineSeriesView.MarkerVisibility = DevExpress.Utils.DefaultBoolean.False; //去掉線條中的圓點(diǎn) radLineSeriesView.Closed = false; //線條不形成閉環(huán) RadarLineChart.Series.Add(seriesArr[i]); } // Flip the diagram (if necessary). RadarDiagram radarDiagram = RadarLineChart.Diagram as RadarDiagram; radarDiagram.StartAngleInDegrees = 0; //開始的角度 radarDiagram.AxisX.WholeRange.MinValue = 0; //設(shè)置角度范圍最小值 radarDiagram.AxisX.WholeRange.MaxValue = 23; //設(shè)置角度范圍最大值 radarDiagram.RotationDirection = RadarDiagramRotationDirection.Clockwise; //數(shù)據(jù)是順時(shí)針還是逆時(shí)針 // Add a title to the chart and hide the legend. ChartTitle chartTitle1 = new ChartTitle(); chartTitle1.Text = "Radar Line Chart"; RadarLineChart.Titles.Add(chartTitle1); RadarLineChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; //隱藏圖例 // Add the chart to the form. RadarLineChart.Dock = DockStyle.Fill; this.Controls.Add(RadarLineChart); // Populate the series with points. Random r = new Random((int)DateTime.Now.Ticks); r.NextDouble(); for (int i = 0; i < seriesArr.Length; i++) { for (int k = 0; k < points; k++) { double yValue = 100 * r.NextDouble(); pintValuesList[i].Add(new SeriesPoint(k * 24.0 / points, yValue)); } seriesArr[i].Points.AddRange(pintValuesList[i].ToArray()); seriesArr[i].LabelsVisibility = DevExpress.Utils.DefaultBoolean.False; //隱藏?cái)?shù)據(jù)點(diǎn)的標(biāo)簽顯示 } } } }
運(yùn)行效果圖,如下:
原文鏈接:https://blog.csdn.net/zlbdmm/article/details/122982729
相關(guān)推薦
- 2023-10-14 c/c++--字節(jié)對(duì)齊(byte alignment)
- 2022-11-17 啟動(dòng)VMware時(shí)遇到“vmx86版本不匹配問題”的完美處理方法_VMware
- 2022-04-04 iview在Table表格中渲染title文字提示,使用render實(shí)現(xiàn)
- 2022-08-23 一文教會(huì)你調(diào)整Matplotlib子圖的大小_python
- 2022-08-22 Golang實(shí)現(xiàn)快速求冪的方法詳解_Golang
- 2022-04-28 利用shell命令刪除指定的文件的方法_linux shell
- 2022-06-30 React-hooks中的useEffect使用步驟_React
- 2022-04-12 Redis?Server啟動(dòng)過程的詳細(xì)步驟_Redis
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支