Click here to Skip to main content
15,888,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi Members,

does anyone know how can I set chart width to 70% of the container? I have already set my container width to 100% like this: container.Width = Unit.Percentage(100);

This is my codes:
C#
Chart Chart1= new Chart();
                    Chart1.DataSource = dt;
                    Chart1.Width = 800;
                    Chart1.Height = 490;                  

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

                    foreach (DataRow row in dt.Rows)
                        Chart1.Series[0].Points.AddXY(row["STATUS"], new object[] { row["MIN"], row["MAX"], row["25THPERCENTILE"], row["75THPERCENTILE"], row["AVG"], row["50THPRECENTILE"] });

                    //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);

Now currently the chart width is set to pixel. I would like to chart width to be set to percentage.

Question: How can I set chart width to 70%?

Appreciate if someone can help me on this, thanks a lot!!
Posted
Updated 7-Oct-15 15:00pm
v2

1 solution

Try this :
C#
Chart1.Width = Convert.ToInt32(myContainer.Width * 0.7) ;


you have to replace "myContainer" with the Name of your container-Control ...
 
Share this answer
 
v2
Comments
Member 11999641 8-Oct-15 1:32am    
hi Ralf Meier, have tried this but doesn't work. Error occurred.
Ralf Meier 8-Oct-15 6:46am    
Sorry ... I posted with one '=' to much.
Regard the changed code ...
Ralf Meier 9-Oct-15 0:28am    
Does it work now ?
... or do you still have a Problem ?

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