簡體   English   中英

如何在圖表頂部顯示數據點值

[英]How do you display a data points value on top of the chart

我正在使用System.Web.UI.DataVisualization.Charting顯示單個系列的點。 我試圖實現的功能類似於IsValueShownAsLabel,除了我希望標簽出現在圖表的頂部,而不是在數據點旁邊。

我嘗試了智能標簽,並設置了標簽樣式,但是這些操作只是更改了標簽在數據點旁邊的位置,即,它是在該點的左側還是右側,而不是該點的實際位置。

我不確定其他地方還是我容易做到的。

經過一番挖掘,我自己找到了答案。

我一直在尋找帶有自定義標簽的輔助X軸。

chart.ChartAreas[0].AxisX2.Enabled = AxisEnabled.True;

然后我遍歷數據點並為每個值添加自定義標簽

for(var i = 0; i < chart.Series[0].Points.Count; i++)
        {
            var lowerValue = i + 1 - .5;
            var upperValue = i + 1 + .5;
            var roundedValue = Math.Round(chart.Series[0].Points[i].YValues.First(), 1);

            secondaryXAxis.CustomLabels.Add(lowerValue, upperValue, roundedValue.ToString(CultureInfo.InvariantCulture));
        }

建議使用-.5和+.5以確保這些點落在所需的線上。 奇跡般有效。

暫無
暫無

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

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