我有一个我在WinForms应用程序中通过图表控件创建的极坐标图表。 X轴类型为距离,Y轴类型为方位角。
我的问题是我不能在中心设置X,Y初始点,即(0,0),它总是出现在不同的地方。如图1所示
如上图所示,方位角值在270处为零,在90处为360,距离在180处为0,在0处为100。 这是我用来创建极坐标图的代码。
public PolarChart()
{
this.WindowState = FormWindowState.Maximized;
InitializeComponent();
Series s0 = new Series("PolarChart");
s0.Color = Color.Gray;
s0.ChartType = SeriesChartType.Polar;
s0.Points.AddXY(0, 0);
chart1.Series.Add(s0);
chart1.Series[0]["PolarDrawingStyle"] = "line";
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = 360;
chart1.ChartAreas[0].AxisX.Interval = 30;
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 100;
chart1.ChartAreas[0].AxisY.Interval = 10;
}
private void btnDisplay_Click(object sender, EventArgs e)
{
TextFieldParser reader = new TextFieldParser("LFPoints.txt");
reader.Delimiters = new string[] { "," };
reader.HasFieldsEnclosedInQuotes = true;
string[] read = reader.ReadFields();
try
{
Series S2 = new Series("Plot");
S2.ChartType = SeriesChartType.Polar;
S2.BorderColor = Color.Red;
if (read != null)
if (read.Length != 0)
{
foreach (string other in read)
{
ComputeDistanceAngle(other, Base);
S2.Points.AddXY(Azimuth, Distance);
}
chart1.Series.Add(S2);
chart1.Series["LFPlot"]["PolarDrawingStyle"] = "marker";
}
else
{
MessageBox.Show("No Graph to Plot");
}
else
MessageBox.Show("No Graph to Plot");
}
catch (Exception)
{
}
}
private void chart1_MouseMove(object sender, MouseEventArgs e)
{
var pos = e.Location;
if (prevPosition.HasValue && pos == prevPosition.Value)
return;
tooltip.RemoveAll();
prevPosition = pos;
var results = chart1.HitTest(pos.X, pos.Y, false,
ChartElementType.PlottingArea);
foreach (var result in results)
{
if (result.ChartElementType == ChartElementType.PlottingArea)
{
var xVal = result.ChartArea.AxisX.PixelPositionToValue(pos.X);
var yVal = result.ChartArea.AxisY.PixelPositionToValue(pos.Y);
tooltip.Show("Azimuth = " + xVal + "\n"+" Distance = " + yVal, this.chart1,
pos.X, pos.Y - 15);
}
}
}
在我经常尝试之后,我开始了解" Crossing"属性。
chart1.ChartAreas[0].AxisX.Crossing = 90;
chart1.ChartAreas[0].AxisY.Crossing = 0;
但我没有得到我需要的东西。所以请帮我绘制极坐标图表中的点,从中心开始用X和Y点。这是我需要极地图表的链接。 enter link description here
我正在使用Visual Studio 2010。