Click here to Skip to main content
13,593,055 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All

I am using asp .net charting for reports.
I just want to set the width of the chart series(bar).
If i retrieve 10 values and assign to chart, width of the bar or series is small and look great.
In some cases if there is only one value, the chart column width is big.
How can i set the width of the bar in the chart using System.Web.UI.DataVisualization.Charting.

Posted 6-Feb-12 18:26pm
Updated 6-Feb-12 19:52pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

May help you

<asp:Chart ID="Chart1" runat="server"

               <asp:Series Name="Series1" Color="Bisque" LegendText="Test" MarkerSize="1"

                   MarkerStyle="Triangle" XValueMember="RegNo" XValueType="String"

                   YValueMembers="Trips" YValueType="Int32">
               <asp:ChartArea Name="ChartArea1">
              <AxisX Title="Vehicle"></AxisX>
              <AxisY Title="Trips"></AxisY>
                   <InnerPlotPosition Height="70" Width="70" X="9.7804" Y="3.35106" />
                   <Area3DStyle Enable3D="True" Rotation="0" WallWidth="0" />

private void BindChart()
       DataTable dt = getData();
       int i = 0;
       foreach (DataRow dr in dt.Rows)
           if (i < 5)
               Chart1.Series[0].Points.AddXY(dr["RegNo"].ToString(), dr["Trips"].ToString());
               Chart1.Series[0].Points[i].ToolTip = dr["RegNo"].ToString() + " - " + dr["Trips"].ToString();
               Chart1.Series[0].Points[i].Label = dr["Trips"].ToString();
       Chart1.Width = Unit.Pixel(dt.Rows.Count * 20);

   public DataTable getData()
       SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["TransportConnectionString"].ConnectionString);
       SqlCommand cmd = new SqlCommand("Select COUNT(TripID) as Trips,RegNo from TRNS.Trip Group By RegNo", con);
       DataTable dt = new DataTable();
       return dt;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03-2016 | 2.8.180618.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100