Reputation: 865
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:
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%?
Upvotes: 2
Views: 1994
Reputation: 46
Can't you specify a client-side Id for the chart and specify the width with css?
<asp:Chart ID="myChart" runat="server" ClientIDMode="Static">
And then in your css:
#myChart{
width:70%;
}
Upvotes: 0
Reputation: 13188
Apparently Chart
control accepts only UnitType.Pixel
.
This works fine:
Unit unit1 = new Unit(70, UnitType.Pixel);
Chart1.Width = unit1;
But this,
Unit unit2 = new Unit(70, UnitType.Percentage);
Chart1.Width = unit2;
Throws an exception:
System.ArgumentException was unhandled by user code HResult=-2147024809 Message=Chart width MUST be set in pixels. Source=System.Web.DataVisualization StackTrace: at System.Web.UI.DataVisualization.Charting.Chart.set_Width(Unit value) at WebApplication63.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\WebApplication63\WebApplication63\WebForm1.aspx.cs:line 16 at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:
Upvotes: 2