本文介绍了将一个c#极坐标图设置为特定数量的环和段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#(没有库)中创建一个具有固定大小的环和段的极坐标图。也可以改变侧面的数字,使0在右边?如果不可能在C#是有一个库吗?



解决方案

这不难用 MSChart p>

您可以使用 Polar ChartType 并设置两个 Axes 达到您想要的效果:





这里是一个例子;添加图表chart1 给您Form并设置如下:

  Series s = chart1.Series [0]; //对默认系列的引用
ChartArea ca = chart1.ChartAreas [0]; //对默认图表区域的引用。
Axis ax = ca.AxisX; // and the ewo ..
Axis ay = ca.AxisY; // ..axes

s.ChartType = SeriesChartType.Polar; //设置系列的图表类型
s.MarkerStyle = MarkerStyle.Circle; // display data as ..
s.SetCustomProperty(PolarDrawingStyle,Marker); // ..分,而不是线

让步幅从0°到360° 15°
旋转90°时,设置以下轴值:

  ax.Minimum = 
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 (最大 - 最小)/间隔 c>。并且对于 Y轴,环的数量是相同的。要控制两者,最好全部设置,而不是依赖默认的自动设置!



想要一个空的中心你应该




  • 在y-最小值或-1或-2间隔中包含缓冲区
  • $ b
$ $ b b
$ b

作为一种替代方法,您可以向中心添加一个虚拟数据点,并为其设置样式:

  int cc = s.Points.AddXY(0,ay.Minimum); 
DataPoint dpc = s.Points [cc];
dpc.MarkerColor = Color.White;
dpc.MarkerSize = centerwidth; //巧妙!

要为 centerwidth 找到合适的大小将需要测试,或者,如果你想扩展工作,在 xxxPaint 事件中做一个测量;这超出了这个答案的范围。


I want to create a polar diagram in C# (no libary) that has a fixed amout of rings and segments. Is it also possible to change the digrees on the side so the 0 is on the right? If it is not possible in C# is there a libary for it?

解决方案

This is not hard at all using the MSChart control.

You can use its Polar ChartType and set the various properties of the two Axes to achieve what you want:

Here is an example; add a Chart chart1 to you Form and set it up like this:

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

To let the spokes go from 0° to 360° in steps of 15°with a rotation of 90° set these axes values:

ax.Minimum = 0;
ax.Maximum = 360;
ax.Interval = 15;
ax.Crossing = 90;

Controlling the rings is trickier, as it eventually must take your data values into account! Assuming y-values going from 0-100 we can use these settings to get 10 rings:

ay.Minimum = 0;
ay.Maximum = 100;
ay.Interval = (ay.Maximum - ay.Minimum) / 10;

If your data values have a different range you should adapt these values!

So the number of spokes is (Maximum - Minimum) / Interval for the X-Axis. And the number of rings is the same but for the Y-Axis. To control both is is best to set them all and not rely on the default automatic setting!

If you want an empty center you should

  • include a buffer in the y-mimimum value or -1 or -2 intervals
  • make 1 or 2 rings more
  • draw a white circle over the center, which is a little tricky..

As an alternative you could add a dummy Datapoint to the center and style it:

int cc = s.Points.AddXY(0, ay.Minimum);
DataPoint dpc = s.Points[cc];
dpc.MarkerColor = Color.White;
dpc.MarkerSize = centerwidth;  // tricky!

To find the right size for centerwidth you would have to either test or, if you want scaling to work, do a measurement in a xxxPaint event; this goes beyond the scope of this answer..

这篇关于将一个c#极坐标图设置为特定数量的环和段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 05:20