<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Chart ID="Chart1" runat="server" BackColor="CadetBlue"
BackGradientStyle="TopBottom" Height="406px" Width="865px" >
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" Name="Legend1" Title="图例">
</asp:Legend>
</Legends>
<Titles>
<asp:Title Font="微软雅黑, 16pt" Name="Title1" Text="季节销量图表">
</asp:Title>
</Titles>
<Series>
<asp:Series Name="Series1" ChartArea="ChartArea1">
</asp:Series>
<asp:Series Name="Series2" ChartArea="ChartArea1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.DataVisualization.Charting;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connstr = "Data Source=.;Initial Catalog=car;User ID=sa;pwd=123 ";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string sqlstr = "SELECT jijie,Volume1, Volume2 FROM Table_1";
SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
//设置图表的数据源
Chart1.DataSource = dt;
//设置图表Y轴对应项
Chart1.Series[0].YValueMembers = "Volume1";
Chart1.Series[1].YValueMembers = "Volume2";
//设置图表X轴对应项
Chart1.Series[0].XValueMember = "jijie";
//绑定数据
Chart1.DataBind();
Chart1.Series[0].IsValueShownAsLabel = true;
Chart1.Series[1].IsValueShownAsLabel = true;
Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
Draw as 3D Cylinder
Chart1.Series[0]["DrawingStyle"] = "Cylinder";
//像素点见宽度
Chart1.Series[0]["PointWidth"] = "0.8";
//是否显示数值
Chart1.Series[0].IsValueShownAsLabel = true;
//X轴数据显示间隔
Chart1.ChartAreas[0].AxisX.Interval = 1;
//直角坐标显示,
Chart1.ChartAreas[0].Area3DStyle.IsRightAngleAxes = false;
//是否群集在一起
Chart1.ChartAreas[0].Area3DStyle.IsClustered = false;
//转动X轴角度
Chart1.ChartAreas[0].Area3DStyle.Inclination = 40;
//转动Y轴角度
Chart1.ChartAreas[0].Area3DStyle.Rotation = 20;
foreach ( Series ser in Chart1.Series)
{
//柱形宽度
ser["PixelPointWidth"] = "40";
//像素点深度
ser["PixelPointDepth"] = "80";
//像素点间隙深度
ser["PixelPointGapDepth"] = "10";
}
}
}