有谁知道如何将图表定位在页面的中心?该图表现在始终显示在页面左侧。我的图表是在标签面板中动态创建的,我希望我的图表位于页面的中心。
这是我的代码:
//Aspx file
<div>
<asp:scriptmanager ID="ScriptManager1" runat="server">
</asp:scriptmanager>
</div>
<asp:updatepanel ID="UpdatePanel1" runat="server" ScrollBars="Horizontal">
<contenttemplate>
<asp:placeholder ID="PlaceHolder1" runat="server"></asp:placeholder>
</contenttemplate>
</asp:updatepanel>
//Cs file
AjaxControlToolkit.TabContainer container = new AjaxControlToolkit.TabContainer();
container.ID = "TabContainer";
container.EnableViewState = false;
container.Tabs.Clear();
foreach (ListItem item in SelectionListBox.Items)
{
if (item.Selected)
{
Label tabContent = new Label();
tabContent.ID = "lbl_tab_";
tabContent.Text += item.Value;
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;
AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
panel.HeaderText += item.Value;
container.Tabs.Add(panel);
panel.Controls.Add(tabContent);
panel.Controls.Add(Chart1);
}
}
PlaceHolder1.Controls.Add(container);
}
public AjaxControlToolkit.TabPanel GetManualTab()
{
AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
return panel;
}
感谢所有人都可以帮助我,非常感谢!!
答案 0 :(得分:0)
在ASPX上取一个div(注意 align 属性)
<div id="divChart" runat="server" align="center" />
修改后面的代码以在最后添加它(在数据绑定之后)
divChart.Controls.Add(Chart1);
这在FF和Chrome以及IE中的预期效果如此。