Click here to Skip to main content
12,505,591 members (55,396 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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 6-Feb-12 18:26pm
froxy1.2K
Updated 6-Feb-12 19:52pm
v2

1 solution

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

Solution 1

May help you

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

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;
   }
  Permalink  

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 | Mobile
Web02 | 2.8.160927.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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