今天小编给大家分享一下C#中如何使用DevExpress的ChartControl实现极坐标图的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

背景

在工控软件的开发中很多业务场景就是使用图表控件展示设备和工艺参数。如下图案例:

实现思路

通常简单的做法是使用图表控件实现,常用的图表控件有开源的ZedGraph,还有付费的TeeChart和DevExpress。常规的曲线图、柱状图、饼图的实现,三个控件都可以很好的实现,建议使用开源的ZedGraph。但是在实现雷达图、极坐标图等特定图表时ZedGraph就不能支持,TeeChart用起来也不是那么完美,对比后发现DevExpress的ChartControl实现还是不错的。

参考代码

本案例是使用的是DevExpress 18.1.3版本,之前在14版本上也试过,但是有一个弊端就是实现极坐标图的时候,第一个点和最后一个点总是自动多一条闭合线,会形成一个闭合的多边形,因此升级了一下版本。在DevExpress中雷达图和极坐标图使用的是父子类的关系,很多属性一致,为了可以自己定义圆盘上的刻度范围,这是采用雷达图实现自定义的极坐标图。

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Diagnostics;usingDevExpress.XtraCharts;namespaceWinTest{publicpartialclassForm1:Form{privateStopwatchsw=newStopwatch();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){sw.Restart();intfontSize=9;//字号intcount=1;//曲线数量intpoints=8;//每条曲线的点数intangleMaxValue=24;//角度最大值intmaxShowPints=30;//最大显示的点数for(inti=0;i<this.Controls.Count;i++){if(this.Controls[i]isChartControl){this.Controls.RemoveAt(i);break;}}//Createanewchart.ChartControlRadarLineChart=newChartControl();//Addaradarseriestoit.Series[]seriesArr=newSeries[count];List<SeriesPoint>[]pintValuesList=newList<SeriesPoint>[count];for(inti=0;i<seriesArr.Length;i++){pintValuesList[i]=newList<SeriesPoint>();seriesArr[i]=newSeries("Series"+i,ViewType.RadarLine);//使用雷达折线图实例化SeriesRadarLineSeriesViewradLineSeriesView=(seriesArr[i].ViewasRadarLineSeriesView);radLineSeriesView.MarkerVisibility=DevExpress.Utils.DefaultBoolean.False;//去掉线条中的圆点radLineSeriesView.Closed=false;//线条不形成闭环RadarLineChart.Series.Add(seriesArr[i]);}//Flipthediagram(ifnecessary).RadarDiagramradarDiagram=RadarLineChart.DiagramasRadarDiagram;radarDiagram.StartAngleInDegrees=0;//开始的角度radarDiagram.AxisX.WholeRange.MinValue=0;//设置角度范围最小值radarDiagram.AxisX.WholeRange.MaxValue=23;//设置角度范围最大值radarDiagram.RotationDirection=RadarDiagramRotationDirection.Clockwise;//数据是顺时针还是逆时针//Addatitletothechartandhidethelegend.ChartTitlechartTitle1=newChartTitle();chartTitle1.Text="RadarLineChart";RadarLineChart.Titles.Add(chartTitle1);RadarLineChart.Legend.Visibility=DevExpress.Utils.DefaultBoolean.False;//隐藏图例//Addthecharttotheform.RadarLineChart.Dock=DockStyle.Fill;this.Controls.Add(RadarLineChart);//Populatetheserieswithpoints.Randomr=newRandom((int)DateTime.Now.Ticks);r.NextDouble();for(inti=0;i<seriesArr.Length;i++){for(intk=0;k<points;k++){doubleyValue=100*r.NextDouble();pintValuesList[i].Add(newSeriesPoint(k*24.0/points,yValue));}seriesArr[i].Points.AddRange(pintValuesList[i].ToArray());seriesArr[i].LabelsVisibility=DevExpress.Utils.DefaultBoolean.False;//隐藏数据点的标签显示}}}}

运行效果图,如下:

以上就是“C#中如何使用DevExpress的ChartControl实现极坐标图”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。