Click here to Skip to main content
15,886,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.


Regards
Froxy
Posted
Updated 6-Feb-12 19:52pm
v2

1 solution

May help you

XML
<asp:Chart ID="Chart1" runat="server"
           Palette="Chocolate">
           <Series>
               <asp:Series Name="Series1" Color="Bisque" LegendText="Test" MarkerSize="1"
                   MarkerStyle="Triangle" XValueMember="RegNo" XValueType="String"
                   YValueMembers="Trips" YValueType="Int32">
               </asp:Series>
           </Series>
           <ChartAreas>
               <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" />
               </asp:ChartArea>
           </ChartAreas>
       </asp:Chart>


C#
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();
           }
           i++;
       }
       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();
       con.Open();
       dt.Load(cmd.ExecuteReader());
       con.Close();
       return dt;
   }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900