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 =





    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 =







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



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




    chrtZipCode.PlotArea.XAxis.LayoutMode =





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




     s0.Appearance.ShowLabels =




     s0.DefaultLabelValue =




     s0.DataYColumn =




     s0.Appearance.LabelAppearance.FillStyle.MainColor =




     s0.Appearance.LabelAppearance.Border.Color =




     s0.Appearance.TextAppearance.TextProperties.Color =





    // Clear series items.





    // Set new items for the series.


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





    ChartSeriesItem seriesItem = new ChartSeriesItem();


         seriesItem.YValue =



         seriesItem.Appearance.Border.Color =










  2. Ves
    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,
    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