簡體   English   中英

MSchart極坐標圖自定義標簽不起作用

[英]MSchart polar chart custom labels not working

默認情況下,極坐標圖表上的角度順時針方向從0到360,但我希望它們逆時針方向(逆時針方向)

chart.ChartAreas[0].AxisX.Title = "Elevation";
chart.ChartAreas[0].AxisY.Title = "Power(dBm)";
chart.ChartAreas[0].BackColor = System.Drawing.Color.FromArgb(211, 223, 240);
chart.ChartAreas[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
chart.ChartAreas[0].AxisY.IsStartedFromZero = false;
chart.PrePaint += new EventHandler<ChartPaintEventArgs>(chart_prePaint);

我試過按照我發現的一些示例代碼更改標簽:

CustomLabelsCollection labels = chart.ChartAreas[0].AxisX.CustomLabels;

if (labels == null) return;

for (int i = 0; i < labels.Count - 1; i++)
{
    if (labels[0].Text == "360") break;
    labels[i].Text = (360 - int.Parse(labels[i].Text)).ToString();
    labels[i].ToolTip = "Angle in Degrees";
}

代碼更改對象中的標簽,但不更改圖表上的標簽。 每次事件被觸發並且我們回到此事件處理程序時,標簽已重置為最初的方式。工具提示已重置。

為了增加混亂,我不確定為什么首先填充CustomLabels對象 - 我沒有這樣做。

知道改變為什么沒有效果?

提前致謝!

如果你想要這樣的東西:..

在此輸入圖像描述

.. CustomLabels確實是實現它的一種方式。 我找不到讓軸反轉的方法..

這是我使用的C#代碼:

Axis ay = chart.ChartAreas[0].AxisY;
ay.LabelStyle.Enabled = false;

Axis ax = chart.ChartAreas[0].AxisX;
ax.CustomLabels.Clear();

int  step = (int)ax.Interval;
if (step == 0) step = 30;

for (int i = 0; i < 360; i+=step)
{
    int a = 360 - i;             // the angle to target
    var cl = new CustomLabel();
    cl.Text = a + "°";
    cl.FromPosition = a + 0.01;  // create a small..
    cl.ToPosition = a - 0.01;    // ..space to place the label !
    ax.CustomLabels.Add(cl);
}

請注意,只有Labels是反轉的, 而不是

要從0開始,只需將循環條件更改為<=並在創建標簽之前檢查i>0

如果您沒有設置Interval我使用默認間隔30 ; 根據需要改變!


默認情況下會創建 CustomLabels集合,因此它不為null但為Count==0 )。 如果你沒有創建任何,那么沒有,原始的AxisLabels正在顯示。 (只顯示一種類型!)

除非你有一個非常好的理由,比如非常動態的數據,你不應該在xxxPaint事件中添加修改任何東西! 它們可能經常被調用,而這些事件實際上只是用於繪圖。 ((有時用於測量))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM