Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
I have created a dynamic box plot chart and it was positioned at the center of the page. I would like to shift the chart 5px to the left.

This is the output of my chart currently:
http://i.stack.imgur.com/fbUPW.jpg</a>[^]

I want to shift the chart slightly to the left, like 5px to the left. Does anyone has any suggestion on how this can be achieved?

I have tried Chart1.Style["right"] = 5.ToString() + "px"; but the chart still stay at the same position.

This is my codes to create the chart:
C#
Chart Chart1 = new Chart();
                                Chart1 .DataSource = dt;

                                System.Web.UI.HtmlControls.HtmlGenericControl Chart1_DIV = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
                                Chart1_DIV.ID = "LVL1RISKCHART_DIV";
                                Chart1_DIV.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
                                Chart1_DIV.Style.Add(HtmlTextWriterStyle.Width, "100%");

                                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["DESC"], new object[] { row["MIN"], row["MAX"], row["25TH_PERCENTILE"], row["75TH_PERCENTILE"], row["50TH_PERCENTILE"], row["AVG"] });
                                                                    
                                //create chartareas
                                ChartArea ca = new ChartArea();
                                ca.AxisX = new Axis();
                                ca.AxisY = new Axis();
                                Chart1.ChartAreas.Add(ca);

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

Any help is greatly appreciated, thanks.
Posted

1 solution

The right property[^] only works if the element has absolute or relative positioning. For statically positioned elements, it has no effect.

It also specifies how far the styled element's right-hand edge should be from the parent element's right-hand edge. That doesn't sound like what you're trying to achieve.

Try using a 2D transform[^]:
C#
Chart1.Style["transform"] = "translateX(-5px)";

// If you need IE9 support:
Chart1.Style["-ms-transform"] = "translateX(-5px)";

http://caniuse.com/#feat=transforms2d[^]
 
Share this answer
 
v2
Comments
Member 11999641 30-Nov-15 11:31am    
hi @Richard Deeming, thanks for your reply! i tried to use the methods u suggested but still get the same output.

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