有没有办法在极坐标图上画一个点 [英] Is there a way to draw a Point on a Polar Chart

查看:19
本文介绍了有没有办法在极坐标图上画一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在环和线段线之间的每个交叉点"上添加一个彩色点(红色或绿色).有没有比制作只有两个数据点的 240 系列更简单的方法?

解决方案

1 - 无需创建不同的 Series.只需在您想要的位置添加您想要的 DataPoints!这是最简单的方法,因为您已经知道这些值.

2 - 作为替代,您可以使用 xxxPaint 事件并绘制实心圆圈(或您喜欢的任何东西..).为此,您需要将值转换为像素.这可以通常通过AxisX/AxisY.ValueToPixelPosition 方法实现.但是对于 Polar Charts 这将不起作用.相反,您需要自己计算像素坐标..

第二种方式有点难,但当然会让你更好地控制你绘制的点的风格..

这是添加DataPoints的结果:

第一个版本的示例代码;首先,我们设置一个带有轴属性的极坐标图:

Chart chart = chart2;chart.Series.Clear();ChartArea ca = chart.ChartAreas[0];轴 ax = ca.AxisX;轴 ay = ca.AxisY;ax.Minimum = 0;ax.Maximum = 360;ax.Interval = 15;//15°间隔ax.Crossing = 0;//从顶部开始分段!ay.Minimum = 0;ay.最大值 = 10;ay.Interval = 1;系列 s0 = chart.Series.Add("points");s0.MarkerStyle = MarkerStyle.Circle;s0.SetCustomProperty("PolarDrawingStyle", "Marker");s0.MarkerSize = 6;s0.MarkerColor = Color.Teal;s0.ChartType = SeriesChartType.Polar;

然后我们在交叉点添加点,最后为其中一个设置样式以表明它们都可以不同..:

for (double vx = ax.Minimum; vx 

当然,如果您不想首先添加 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆