Autosizing bar chart

Thread is closed for posting
2 posts, 0 answers
  1. Angel Hawks
    Angel Hawks avatar
    1 posts
    Member since:
    Mar 2010

    Posted 22 Mar 2010 Link to this post

    I have a very long list of XAxis items dynamically added to the chart at run time.  I am unable to find the correct setting to allow the chart to vertically resize to fit them all.  Please help.
    private void UpdateChrtZipCodes(DataSet ds)

     

    {

        chrtZipCode.Legend.Visible =

    false;

     

         chrtZipCode.PlotArea.XAxis.Clear();

         

    EmptySeriesMessage message = chrtZipCode.PlotArea.EmptySeriesMessage;

     

         message.TextBlock.Text =

    "No Data Available.";

     

     

     

    //if (ds.Tables[0].Rows.Count > 20)

     

     

    // chrtZipCode.Height = (ds.Tables[0].Rows.Count * 20);  tried this and it made it too long

        

    chrtZipCode.AutoLayout = true;

     

        chrtZipCode.PlotArea.XAxis.AutoScale =

    false;

     

     

     

     

     

    foreach (DataRow dbRow in ds.Tables[0].Rows)

    {

        chrtZipCode.PlotArea.XAxis.AddItem(

    new ChartAxisItem(dbRow["ZipCode"].ToString()));

     

     

     }

    chrtZipCode.PlotArea.XAxis.LayoutMode =

    ChartAxisLayoutMode.Between;

     

     

     

    // Gets the one and the only series in the chart.

     

     

     

    ChartSeries s0 = chrtZipCode.Series.GetSeries(0);

     

     

     

    // If it doesn't exist - create and set it.

     

     

     

    if (s0 == null)

     

     

     {

        s0 = chrtZipCode.CreateSeries(

    string.Empty, Color.Empty, Color.Empty, ChartSeriesType.Bar);

     

     

    }

    s0.Type =

    ChartSeriesType.Bar;

     

     

     s0.Appearance.ShowLabels =

    true;

     

     

     s0.DefaultLabelValue =

    "#Y";

     

     

     s0.DataYColumn =

    "TheCount";

     

     

     s0.Appearance.LabelAppearance.FillStyle.MainColor =

    Color.White;

     

     

     s0.Appearance.LabelAppearance.Border.Color =

    Color.Black;

     

     

     s0.Appearance.TextAppearance.TextProperties.Color =

    Color.Black;

     

     

     

    // Clear series items.

     

    s0.Clear();

     

     

    // Set new items for the series.

     

    foreach (DataRow dbRow in ds.Tables[0].Rows)

     

     

     {

         

    ChartSeriesItem seriesItem = new ChartSeriesItem();

     

         seriesItem.YValue =

    Convert.ToDouble(dbRow["TheCount"]);

     

         seriesItem.Appearance.Border.Color =

    Color.Black;

     

         s0.Items.Add(seriesItem);

     

    }

     

    }

     

     

  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 25 Mar 2010 Link to this post

    Hi Angel,

    Indeed, RadChart will not support auto-sizing. The automatic layout calculation is focused on arranging the chart elements within given bounds, but not on changing the chart size -- this would lead to changing the entire page layout. If you need dynamic chart sizing -- you can set the PlotArea Margins with values in pixels (not percents). Then you can define the approximate space for a single item and multiply it by the number of items. Finally, add the plot area margins (Top and Bottom) and you will get the desired height (for a horizontal bar chart):

    ChartHeight = TopMargin + BottomMargin + NumberOfItems * ItemSpace


    Best regards,
    Ves
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top