.net4.0以前,要想在网页上画个饼图,那还真不是个轻松的活儿,得有点技术含量,比如:可以用System.Drawing下的那些东东,再或者用Silverlight/Flash或第三方控件
现在asp.net 4.0已经把它做成控件了
直接拖到页面就完事了,下面是示例代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApp.Default" EnableViewState="false" %> <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>图表控件</title> </head> <body> <form id="form1" runat="server"> <asp:Chart ID="Chart1" runat="server"> <Series> <asp:Series Name="Series1" ChartType="Pie"> <Points> <asp:DataPoint AxisLabel="IE 6.0" YValues="60.0" /> <asp:DataPoint AxisLabel="IE 7.0" YValues="27.1" /> <asp:DataPoint AxisLabel="Others" YValues="12.9" /> </Points> </asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"> <Area3DStyle Enable3D="true" /> <Position Auto="true" /> </asp:ChartArea> </ChartAreas> </asp:Chart> </form> </body> </html>
运行效果如下: