Click here to Skip to main content
15,888,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi Members,
I have created box plot chart which will be generated dynamically. I am not sure of how I could adjust the height of chartarea of all charts. I tried research online but still could not find a solution to it.

This is my codes:
HTML
Chart Chart1 = new Chart();
                        Chart1.DataSource = tg;
                        Chart1.Width = 600;
                        Chart1.Height = 350;

                        Chart1.Series.Add(new Series());
                        Chart1.Series[0].ChartType = SeriesChartType.BoxPlot;
                        List<object> lst = tg.AsEnumerable().ToList<object>();

                        foreach (DataRow row in tg.Rows)
                            Chart1.Series[0].Points.AddXY(row["VALUE"], new object[] { row["Min"], row["Max"], row["Avg"], row["Percentile25"], row["Percentile50"], row["Percentile75"] });

                        Chart1.Series[0]["PixelPointWidth"] = "38";
                        string title = (tg.Rows[0]["TITLE"].ToString());
                        Chart1.Titles.Add(title);

                        //create chartareas
                        ChartArea ca = new ChartArea();

                        ca.AxisX = new Axis();
                        ca.AxisX.MajorGrid.Enabled = false;
                        ca.AxisY = new Axis();
                        ca.AxisY.MajorGrid.Enabled = false;
                        Chart1.ChartAreas.Add(ca);

                        //databind
                        Chart1.DataBind();
                        Chart1.Visible = true;

                        panel.Controls.Add(Chart1);


Question: How to set the height of chartarea of a chart?

Appreciate if someone could help me on this. Thanks!

Regards,
Felicia
Posted
Updated 4-Oct-15 7:13am
v5

1 solution

Hi,
the Size of the ChartArea itself could not set directly. Only the Size of the Chart as a Control of your Form.

The ChartArea-Size depends on :
- if the Series-Description is displayed (and the Series-Text itself also)
- the Font-Size of each Kind of description (Series, Axis etc.)
- you want to have an Axis-title
- you want to have a Chart-title

... and perhaps also some more properties of the Chart ...
 
Share this answer
 
Comments
Member 11999641 5-Oct-15 2:00am    
hi Ralf Meier, how do I make sure that the axis x label wouldn't affect my chartarea height? Thanks for your reply! becos now I have many charts, some charts with longer axis x label will have shorter chartarea height. I want to have all charts with the same chartarea height. Do you have any solution for this?
Ralf Meier 5-Oct-15 2:05am    
You can't control that by yourself. It is a mechanism inside the Chart-Control.
But what you could do :
- you switch of all (or most of) descriptions inside the control and create it manually outside the Chart-Control with Labels (sized and positioned by yourself). In this case the Chartarea-Size doesn't change by this because it isn't effected ...
vrushali Kulkarni 13-Jun-23 6:44am    
if I want to add Axis title in ChartArea how to do it

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