This is a migrated thread and some comments may be shown as answers.

Autosizing bar chart

1 Answer 62 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Angel Hawks
Top achievements
Rank 1
Angel Hawks asked on 23 Mar 2010, 12:53 AM
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);

 

}

 

}

 

 

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 25 Mar 2010, 01:20 PM
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.
Tags
Chart (Obsolete)
Asked by
Angel Hawks
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or