Click here to Skip to main content
15,886,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

does anyone know how can I position the chart at the center of the page? The chart always appear on the left of the page right now.

This is my codes:
HTML
Chart Chart1 = new Chart();
                    Chart1.DataSource = dt;
                    Chart1.Width = 715;
                    Chart1.Height = 450;

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

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

                    //create chartareas
                    ChartArea ca = new ChartArea();
                    ca .AxisX = new Axis();
                    ca .AxisY = new Axis();
                    Chart1.ChartAreas.Add(ca);

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

Appreciate if anyone can help me on this, thanks a lot!!

Regards,
Felicia
Posted

1 solution

Try it like this :
C#
this.Chart1.Location = new Point((this.Width - this.Chart1.Width) / 2, (this.Height - this.Chart1.Height) / 2) ;
 
Share this answer
 
v3
Comments
Member 11999641 7-Oct-15 1:36am    
hi Ralf Meier, sorry what is 'this' that is inside the codes you wrote?
Ralf Meier 7-Oct-15 3:37am    
... the Instance of your Page / Form / Object to whom Chart1 belongs
Ralf Meier 9-Oct-15 0:31am    
Does it work now for you ?
Why don't you give a Feedback ?

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