Chart控件的使用实例

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;
}

}
}
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值