Display Values on Bars of a Bar chart in asp.net

hungrycoder picture hungrycoder · Dec 12, 2012 · Viewed 27.9k times · Source

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.

Bar Chart with values on Bar in asp.net

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);

Answer

jbl picture jbl · Dec 12, 2012

You may try :

I want to display values on the top of the bars in asp.net chart.

myHorizontalSeries.IsValueShownAsLabel = true;

Also I want to hide the x axis while displaying it.

c.ChartAreas[0].AxisX.Enabled = AxisEnabled.False;