<asp:Chart runat="server">
<Legends>
<asp:Legend Title="金牌榜"></asp:Legend>
</Legends>
<Series>
<asp:Series>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
</div>
</form>
</body>
</html>
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
//add
using System.Drawing;
public partial class chart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = CreatData();
GetStyle1(dt);
GetStyle2(dt);
GetStyle3(dt);
GetStyle4(dt);
}
protected void GetStyle1(DataTable dt)
{
#region 折线图
Chart1.DataSource = dt;//绑定数据
Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;//设置图表类型
Chart1.Series[0].XValueMember = "Country";//X轴数据成员列
Chart1.Series[0].YValueMembers = "Score";//Y轴数据成员列
Chart1.ChartAreas["ChartArea1"].AxisX.Title = "国家";//X轴标题
Chart1.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远
Chart1.ChartAreas["ChartArea1"].AxisY.Title = "金牌";//X轴标题
Chart1.ChartAreas["ChartArea1"].AxisY.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X轴数据的间距
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线
Chart1.Series[0].IsValueShownAsLabel = true;//显示坐标值
#endregion
}
protected void GetStyle2(DataTable dt)
{
#region 样条图(平滑曲线)
Chart2.DataSource = dt;//绑定数据
Chart2.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Spline;//设置图表类型
Chart2.Series["Series1"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Cross;//设置点的样式,十字形
Chart2.Series[0].XValueMember = "Country";//X轴数据成员列
Chart2.Series[0].YValueMembers = "Score";//Y轴数据成员列
Chart2.ChartAreas["ChartArea1"].AxisX.Title = "国家";//X轴标题
Chart2.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远
Chart2.ChartAreas["ChartArea1"].AxisY.Title = "金牌";//X轴标题
Chart2.ChartAreas["ChartArea1"].AxisY.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远
Chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X轴数据的间距
Chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线
Chart2.Series[0].IsValueShownAsLabel = true;//显示坐标值
#endregion
}