【发布时间】:2016-08-14 09:12:28
【问题描述】:
【问题讨论】:
【问题讨论】:
使用MSChart 控件一点也不难。
你可以使用它的Polar ChartType,并设置两个Axes的各种属性来达到你想要的效果:
这是一个例子;为你添加一个Chart chart1 并设置如下:
Series s = chart1.Series[0]; // a reference to the default series
ChartArea ca = chart1.ChartAreas[0]; // a reference to the default chart area..
Axis ax = ca.AxisX; // and the ewo..
Axis ay = ca.AxisY; // ..axes
s.ChartType = SeriesChartType.Polar; // set the charttype of the series
s.MarkerStyle = MarkerStyle.Circle; // display data as..
s.SetCustomProperty("PolarDrawingStyle", "Marker"); //.. points, not lines
让辐条以 15° 的步长从 0° 转到 360° 旋转 90° 设置这些轴值:
ax.Minimum = 0;
ax.Maximum = 360;
ax.Interval = 15;
ax.Crossing = 90;
控制环比较棘手,因为它最终必须考虑您的数据值! 假设 y 值在 0-100 之间,我们可以使用这些设置来获得 10 个环:
ay.Minimum = 0;
ay.Maximum = 100;
ay.Interval = (ay.Maximum - ay.Minimum) / 10;
如果您的数据值有不同的范围,您应该调整这些值!
因此,X-Axis 的辐条数为 (Maximum - Minimum) / Interval。除了Y-Axis,环的数量是相同的。要同时控制两者,最好全部设置,不要依赖默认的自动设置!
如果你想要一个空的中心,你应该
作为替代方案,您可以在中心添加一个虚拟数据点并为其设置样式:
int cc = s.Points.AddXY(0, ay.Minimum);
DataPoint dpc = s.Points[cc];
dpc.MarkerColor = Color.White;
dpc.MarkerSize = centerwidth; // tricky!
要为centerwidth 找到合适的尺寸,您必须进行测试,或者,如果您想要缩放工作,请在xxxPaint 事件中进行测量;这超出了这个答案的范围..
【讨论】:
这在winforms 中使用GDI 很容易实现。创建一个新的 UserControl,覆盖 OnPaint 功能:
---------------- 编辑 ------------------ 创建一个新的UserControl:右键项目->添加->用户控件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Blue, 0, 0, this.Width, this.Height);
e.Graphics.DrawString("90", this.Font, Brushes.Black, new PointF(0, 0));
e.Graphics.DrawLine(Pens.Red, 0,0, this.Width, this.Height );
}
}
}
【讨论】: