有没有办法在极坐标图上画点 [英] Is there a way to draw a Point on a Polar Chart
问题描述
我想在圆环和分段线之间的每个交叉处添加一个彩色点(红色或绿色)。有没有比制作只有两个数据点的240系列更简单的方法?
1-无需创建其他 Series
。只需在所需位置添加所需的 DataPoints
!这是最简单的方法,因为您已经知道值了。
2-另一种方法是,可以使用 xxxPaint
事件并绘制实心圆(或您喜欢的任何一个..)。为此,您需要将值转换为像素。通常可以使用 AxisX / AxisY.ValueToPixelPosition
方法来实现。 但是对于极谱图
,这将不起作用。取而代之的是,您需要自己计算像素坐标。
第二种方法比较难,但是当然可以让您更好地控制绘制点的样式..
这里是添加 DataPoints
的结果:
第一个版本的示例代码;首先,我们建立一个具有其轴属性的极坐标图:
图表图= chart2;
chart.Series.Clear();
ChartArea ca = chart.ChartAreas [0];
Axis ax = ca.AxisX;
Axis ay = ca.AxisY;
轴,最小值= 0;
轴,最大值= 360;
ax.Interval = 15; // 15°间隔
ax.Crossing = 0; //从顶部开始细分!
ay.Minimum = 0;
ay.Maximum = 10;
ay.Interval = 1;
Series s0 = chart.Series.Add( points);
s0.MarkerStyle = MarkerStyle.Circle;
s0.SetCustomProperty( PolarDrawingStyle, Marker);
s0.MarkerSize = 6;
s0.MarkerColor = Color.Teal;
s0.ChartType = SeriesChartType.Polar;
然后我们在交叉口处添加点,最后对其中一个点进行样式设置以显示它们都可以会有所不同..:
为(double vx = ax.Minimum; vx< ax.Maximum; vx + = ax。间隔)
for(双vy = ay.Minimum; vy< = ay.Maximum; vy + = ay.Interval)
s0.Points.AddXY(vx,vy);
s0.Points [333] .MarkerColor = Color.Red;
s0.Points [333] .MarkerSize = 12;
用于计算像素坐标的代码
或者,如果您不想首先添加 DataPoints
,您可以像在添加它们的循环中那样计算值来替换它们。
I want to add a colored point (red or green) on every "crossing" between the rings and segment lines. Is there a simpler way than making 240 Series which just have two datapoints?
1 - There is no need to create different Series
. Just add the DataPoints
you want at the spots you want! This is the easiest way, since you already know the values.
2 - As an alternative you can use a xxxPaint
event and draw filled circles (or whatever you fancy..). For this you need to convert the values to pixels. This can usually be achieved with the AxisX/AxisY.ValueToPixelPosition
methods. However for Polar Charts
this will not work. Instead you need to calculate the pixel coordinates yourself..
The 2nd way is a bit harder, but of course will give you more control over the style of the points you draw..
Here is the result of adding DataPoints
:
Example code for the 1st version; first we set up a polar chart with its axis properties:
Chart chart = chart2;
chart.Series.Clear();
ChartArea ca = chart.ChartAreas[0];
Axis ax = ca.AxisX;
Axis ay = ca.AxisY;
ax.Minimum = 0;
ax.Maximum = 360;
ax.Interval = 15; // 15° interval
ax.Crossing = 0; // start the segments at the top!
ay.Minimum = 0;
ay.Maximum = 10;
ay.Interval = 1;
Series s0 = chart.Series.Add("points");
s0.MarkerStyle = MarkerStyle.Circle;
s0.SetCustomProperty("PolarDrawingStyle", "Marker");
s0.MarkerSize = 6;
s0.MarkerColor = Color.Teal;
s0.ChartType = SeriesChartType.Polar;
And then we add the points at the crossings and finally style one of them to show that they all can be different..:
for (double vx = ax.Minimum; vx < ax.Maximum; vx += ax.Interval)
for (double vy = ay.Minimum; vy <= ay.Maximum; vy += ay.Interval)
s0.Points.AddXY(vx, vy);
s0.Points[333].MarkerColor = Color.Red;
s0.Points[333].MarkerSize = 12;
For the code to calculate the pixel coordinates see this post!
Using the function in the link and this PrePaint
event:
private void chart2_PrePaint(object sender, ChartPaintEventArgs e)
{
Chart chart = chart2;
ChartArea ca = chart.ChartAreas[0];
Series s0 = chart.Series["points"];
foreach (DataPoint dp in s0.Points)
{
PointF pt = PolarValueToPixelPosition(dp, chart, ca);
e.ChartGraphics.Graphics.DrawEllipse(Pens.OrangeRed, pt.X - 5, pt.Y - 5, 9, 9);
}
}
we can adorn each point with a circle:
Or course, if you don't want to add the DataPoints
in the first place, you can replace them by calculating the values like I did in the loops that added them..
这篇关于有没有办法在极坐标图上画点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!