ChartTest.aspx:
<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="ChartTest.aspx.cs"Inherits="UserManager.Test.ChartTest"%>
<%@RegisterAssembly="System.Web.DataVisualization,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting"TagPrefix="asp"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<center>
<asp:ScriptManagerID="ScriptManager1"runat="server">
</asp:ScriptManager>
<asp:UpdatePanelrunat="server">
<ContentTemplate>
<asp:ChartID="Chart1"runat="server"Height="496px"Width="612px"ImageLocation="~/TempImages/ChartPic_#SEQ(300,3)"
BorderDashStyle="Solid"BackSecondaryColor="White"BackGradientStyle="VerticalCenter"
BorderWidth="2px"BackColor="211,223,240"BorderColor="#1A3B69"
onclick="Chart1_Click">
<Legends>
<asp:LegendIsTextAutoFit="False"Name="Default"BackColor="Transparent"TitleAlignment="Center"
Font="TrebuchetMS,8.25pt,style=Bold">
</asp:Legend>
</Legends>
<BorderSkinSkinStyle="Emboss"></BorderSkin>
<Series>
</Series>
<ChartAreas>
<asp:ChartAreaName="ChartArea1"BorderColor="64,64,64,64"BorderDashStyle="Solid"
BackSecondaryColor="White"BackColor="64,165,191,228"ShadowColor="Transparent"
BackGradientStyle="TopBottom">
<Area3DStyleRotation="10"Perspective="10"Inclination="15"IsRightAngleAxes="False"
WallWidth="0"IsClustered="False"></Area3DStyle>
<AxisYLineColor="64,64,64,64">
<LabelStyleFont="TrebuchetMS,8.25pt,style=Bold"/>
<MajorGridLineColor="64,64,64,64"/>
</AxisY>
<AxisXLineColor="64,64,64,64">
<LabelStyleFont="TrebuchetMS,8.25pt,style=Bold"/>
<MajorGridLineColor="64,64,64,64"/>
</AxisX>
</asp:ChartArea>
</ChartAreas>
<Titles>
<asp:TitleText="我的一家"/>
</Titles>
</asp:Chart>
</ContentTemplate>
</asp:UpdatePanel>
</center>
</div>
</form>
</body>
</html>
ChartTest.aspx.cs:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data;
usingSystem.Web.UI.DataVisualization.Charting;
namespaceUserManager.Test
{
publicpartialclassChartTest:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
//this.Chart1.Click+=newImageMapEventHandler(Chart1_Click);
Seriesseries=newSeries("年龄");
//设置图表类型
series.ChartType=SeriesChartType.Column;
series.BorderWidth=7;
series.ShadowOffset=2;
series.Points.AddY(44);
series.Points.AddY(43);
series.Points.AddY(24);
series.Points.AddY(20);
series.Points.AddY(23);
//X轴显示的名称
series.Points[0].AxisLabel="爸爸";
series.Points[1].AxisLabel="妈妈";
series.Points[2].AxisLabel="陈太汉";
series.Points[3].AxisLabel="陈姗";
series.Points[4].AxisLabel="陈晓玲";
//顶部显示的数字
series.Points[0].Label="44";
series.Points[1].Label="43";
series.Points[2].Label="24";
series.Points[3].Label="20";
series.Points[4].Label="23";
//鼠标放上去的提示内容
series.Points[0].ToolTip="44";
series.Points[1].ToolTip="43";
series.Points[2].ToolTip="24";
series.Points[3].ToolTip="20";
series.Points[4].ToolTip="23";
Seriesseries1=newSeries("其他");
series1.ChartType=SeriesChartType.Column;
series1.BorderWidth=3;
series1.ShadowOffset=2;
series1.Points.AddY(144);
series1.Points.AddY(143);
series1.Points.AddY(124);
series1.Points.AddY(120);
series1.Points.AddY(123);
series1.Points[0].Label="144";
series1.Points[1].Label="143";
series1.Points[2].Label="124";
series1.Points[3].Label="120";
series1.Points[4].Label="123";
series1.Points[0].ToolTip="144";
series1.Points[1].ToolTip="143";
series1.Points[2].ToolTip="124";
series1.Points[3].ToolTip="120";
series1.Points[4].ToolTip="123";
series1.YAxisType=AxisType.Primary;
series1.YValueType=ChartValueType.Time;
Chart1.Series.Add(series);
Chart1.Series.Add(series1);
//按照升序的方式排列
Chart1.Series[0].Sort(PointSortOrder.Ascending);
Chart1.Series[1].Sort(PointSortOrder.Ascending);
foreach(SeriesserieinChart1.Series)
{
serie.PostBackValue="#AXISLABEL"+";#INDEX";
}
}
protected void Chart1_Click(object sender, ImageMapEventArgs e)
{
string str = e.PostBackValue;
}
}
}