C# 在 asp.net 中的条形图的条形上显示值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13839359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display Values on Bars of a Bar chart in asp.net
提问by hungrycoder
I want to display values on the top of the bars in asp.net chart. Also I want to hide the x axis while displaying it. For mock up please see the image below. Thanks.
我想在 asp.net 图表中的条形顶部显示值。另外我想在显示时隐藏 x 轴。对于模拟,请参见下图。谢谢。


I tried following but doesn't work.
我尝试遵循但不起作用。
var c = HorizontalChart;
//c.ChartAreas.Add(new ChartArea("HChartArea"));
//c.ChartAreas[0].BackHatchStyle = ChartHatchStyle.None;
c.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
c.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
c.ChartAreas[0].AxisY.CustomLabels="Code here for Lable values" <-------------
c.Width = 300;
c.Height = 300;
Series myHorizontalSeries = new Series();
myHorizontalSeries.Color = System.Drawing.Color.Blue;
myHorizontalSeries.ChartType = SeriesChartType.Bar;
myHorizontalSeries.Points.DataBindXY(new string[] { "one", "two", "three" }, new int[] { 1, 2, 3 });
c.Series.Add(myHorizontalSeries);
采纳答案by V4Vendetta
You should try setting the Axis Enabled property to false
您应该尝试将 Axis Enabled 属性设置为 false
c.ChartAreas[0].AxisX.Enabled = AxisEnabled.False;
To show the values you set the IsValueShownAsLabelproperty of the series to true
要显示值,您将IsValueShownAsLabel系列的属性设置为true
回答by jbl
You may try :
你可以试试:
I want to display values on the top of the bars in asp.net chart.
我想在 asp.net 图表中的条形顶部显示值。
myHorizontalSeries.IsValueShownAsLabel = true;
Also I want to hide the x axis while displaying it.
另外我想在显示时隐藏 x 轴。
c.ChartAreas[0].AxisX.Enabled = AxisEnabled.False;
回答by Drako
another example you can show values like labels
另一个示例,您可以显示标签等值
c.Series[myHorizontalSeries].Label = "#VALY";
Hope I've helped.
希望我有所帮助。

