asp.net微软图表控件使用示例代码分享(3)

protected void GetStyle3(DataTable dt)
    {
        #region 条形图
        Chart3.DataSource = dt;//绑定数据
        Chart3.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;//设置图表类型
        Chart3.Series[0].XValueMember = "Country";//X轴数据成员列
        Chart3.Series[0].YValueMembers = "Score";//Y轴数据成员列
        Chart3.ChartAreas["ChartArea1"].AxisX.Title = "国家";//X轴标题
        Chart3.ChartAreas["ChartArea1"].AxisX.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远
        Chart3.ChartAreas["ChartArea1"].AxisY.Title = "金牌";//X轴标题
        Chart3.ChartAreas["ChartArea1"].AxisY.TitleAlignment = StringAlignment.Far;//设置Y轴标题的名称所在位置位远
        Chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1;//X轴数据的间距
        Chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;//不显示竖着的分割线
        Chart3.Series[0].IsValueShownAsLabel = true;//显示坐标值
        #endregion
    }


    protected void GetStyle4(DataTable dt)
    {
        #region 饼形图
        Chart4.DataSource = dt;//绑定数据
        Chart4.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;//设置图表类型
        Chart4.Series[0].XValueMember = "Country";//X轴数据成员列
        Chart4.Series[0].YValueMembers = "Score";//Y轴数据成员列
        Chart4.Series[0].LegendMapAreaAttributes = "Country"; //显示国家
        Chart4.Series[0].IsValueShownAsLabel = true;//显示坐标值
        #endregion

}
    /// <summary>
    /// 创建一张二维数据表
    /// </summary>
    /// <returns>Datatable类型的数据表</returns>
    protected DataTable CreatData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Country", System.Type.GetType("System.String"));
        dt.Columns.Add("Score", System.Type.GetType("System.String"));
        string[] n = new string[] { "中国","美国", "俄罗斯", "英国" };
        string[] c = new string[] { "85","80", "50", "35" };
        for (int i = 0; i < 4; i++)
        {
            DataRow dr = dt.NewRow();
            dr["Country"] = n[i];
            dr["Score"] = c[i];
            dt.Rows.Add(dr);
        }
        return dt;
    }
}

asp.net微软图表控件使用示例代码分享

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzpfp.html