Put the below code in default.aspx Page.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
h2 { margin-left:5px; }
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
.box { float:left; width:300px; margin:10px; padding:10px; border:1px solid #ccc; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="clearfix">
<h2>Chart Configuration</h2>
<div style="float:left;width:340px;">
<div class="box">
<h3>Chart type</h3>
<p>
<asp:DropDownList ID="ddlChartType" runat="server" AutoPostBack="True">
</asp:DropDownList>
</p>
</div>
<div class="box">
<h3>Number of values</h3>
<p>
<asp:RadioButtonList ID="rblValueCount" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True" Value="10">10 Values</asp:ListItem>
<asp:ListItem Value="20">20 Values</asp:ListItem>
<asp:ListItem Value="50">50 Values</asp:ListItem>
<asp:ListItem Value="100">100 Values</asp:ListItem>
<asp:ListItem Value="500">500 Values</asp:ListItem>
</asp:RadioButtonList>
</p>
</div>
</div>
<div class="box">
<h3>3D Settings</h3>
<p>
<asp:CheckBox ID="cbUse3D" runat="server" AutoPostBack="True" Text="Use 3D Chart" />
</p>
<h4>Inclination angle</h4>
<p>
<asp:RadioButtonList ID="rblInclinationAngle" runat="server" AutoPostBack="True">
<asp:ListItem Value="-90">-90°</asp:ListItem>
<asp:ListItem Value="-50">-50°</asp:ListItem>
<asp:ListItem Value="-20">-20°</asp:ListItem>
<asp:ListItem Value="0">0°</asp:ListItem>
<asp:ListItem Selected="True" Value="20">20°</asp:ListItem>
<asp:ListItem Value="50">50°</asp:ListItem>
<asp:ListItem Value="90">90°</asp:ListItem>
</asp:RadioButtonList>
</p>
</div>
</div>
<div>
<asp:Chart ID="cTestChart" runat="server" Height="400px" Width="800px">
<Series>
<asp:Series Name="Testing">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<Area3DStyle />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</form>
</body>
</html>
<head runat="server">
<title></title>
<style type="text/css">
h2 { margin-left:5px; }
.clearfix:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.clearfix {
display: inline-block;
}
.box { float:left; width:300px; margin:10px; padding:10px; border:1px solid #ccc; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="clearfix">
<h2>Chart Configuration</h2>
<div style="float:left;width:340px;">
<div class="box">
<h3>Chart type</h3>
<p>
<asp:DropDownList ID="ddlChartType" runat="server" AutoPostBack="True">
</asp:DropDownList>
</p>
</div>
<div class="box">
<h3>Number of values</h3>
<p>
<asp:RadioButtonList ID="rblValueCount" runat="server" AutoPostBack="True">
<asp:ListItem Selected="True" Value="10">10 Values</asp:ListItem>
<asp:ListItem Value="20">20 Values</asp:ListItem>
<asp:ListItem Value="50">50 Values</asp:ListItem>
<asp:ListItem Value="100">100 Values</asp:ListItem>
<asp:ListItem Value="500">500 Values</asp:ListItem>
</asp:RadioButtonList>
</p>
</div>
</div>
<div class="box">
<h3>3D Settings</h3>
<p>
<asp:CheckBox ID="cbUse3D" runat="server" AutoPostBack="True" Text="Use 3D Chart" />
</p>
<h4>Inclination angle</h4>
<p>
<asp:RadioButtonList ID="rblInclinationAngle" runat="server" AutoPostBack="True">
<asp:ListItem Value="-90">-90°</asp:ListItem>
<asp:ListItem Value="-50">-50°</asp:ListItem>
<asp:ListItem Value="-20">-20°</asp:ListItem>
<asp:ListItem Value="0">0°</asp:ListItem>
<asp:ListItem Selected="True" Value="20">20°</asp:ListItem>
<asp:ListItem Value="50">50°</asp:ListItem>
<asp:ListItem Value="90">90°</asp:ListItem>
</asp:RadioButtonList>
</p>
</div>
</div>
<div>
<asp:Chart ID="cTestChart" runat="server" Height="400px" Width="800px">
<Series>
<asp:Series Name="Testing">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<Area3DStyle />
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</form>
</body>
</html>
Put below code in Default.aspx.CS
public partial class Default : System.Web.UI.Page
{
Dictionary<DateTime, int> testData = new Dictionary<DateTime, int>();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
// bind chart type names to ddl
ddlChartType.DataSource = Enum.GetNames(typeof(SeriesChartType));
ddlChartType.DataBind();
}
DataBind();
}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
// define test data
Random rnd = new Random(Guid.NewGuid().GetHashCode());
for (int i = 0; i < Convert.ToInt32(rblValueCount.SelectedValue); i++)
{
testData.Add(DateTime.Now.AddDays(i), rnd.Next(1, 50));
}
cTestChart.Series["Testing"].Points.DataBind(testData, "Key", "Value", string.Empty);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// update chart rendering
cTestChart.Series["Testing"].ChartTypeName = ddlChartType.SelectedValue;
cTestChart.ChartAreas[0].Area3DStyle.Enable3D = cbUse3D.Checked;
cTestChart.ChartAreas[0].Area3DStyle.Inclination = Convert.ToInt32(rblInclinationAngle.SelectedValue);
}
}
{
Dictionary<DateTime, int> testData = new Dictionary<DateTime, int>();
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
// bind chart type names to ddl
ddlChartType.DataSource = Enum.GetNames(typeof(SeriesChartType));
ddlChartType.DataBind();
}
DataBind();
}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
// define test data
Random rnd = new Random(Guid.NewGuid().GetHashCode());
for (int i = 0; i < Convert.ToInt32(rblValueCount.SelectedValue); i++)
{
testData.Add(DateTime.Now.AddDays(i), rnd.Next(1, 50));
}
cTestChart.Series["Testing"].Points.DataBind(testData, "Key", "Value", string.Empty);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// update chart rendering
cTestChart.Series["Testing"].ChartTypeName = ddlChartType.SelectedValue;
cTestChart.ChartAreas[0].Area3DStyle.Enable3D = cbUse3D.Checked;
cTestChart.ChartAreas[0].Area3DStyle.Inclination = Convert.ToInt32(rblInclinationAngle.SelectedValue);
}
}
Build and Debug and check out the 2D and 3D charts............. :)
No comments:
Post a Comment