Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use asp.net Microsoft Chart Control

Shulou Source: shulou.com Published: 2022-06-03 07:42:42 09月30日 Update

This article introduces the knowledge of "how to use asp.net Microsoft Chart Control". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The copy code is as follows:

The copy code is as follows:

MsChart Chart Control

The copy code is as follows:

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 line chart

Chart1.DataSource = dt;// bind data

Chart1.Series ["Series1"] .ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;// sets the chart type

Chart1.Series [0] .XValueMember = "Country"; / / X axis data member column

Chart1.Series [0] .YValueMembers = "Score"; / / Y axis data member column

Chart1.ChartAreas ["ChartArea1"] .AxisX.Title = "country"; / / X axis title

Chart1.ChartAreas ["ChartArea1"] .AxisX.TitleAlignment = StringAlignment.Far;// sets the name of the Y-axis title in a position far away

Chart1.ChartAreas ["ChartArea1"] .AxisY.Title = "Gold"; / / X axis title

Chart1.ChartAreas ["ChartArea1"] .AxisY.TitleAlignment = StringAlignment.Far;// sets the name of the Y-axis title in a position far away

Chart1.ChartAreas ["ChartArea1"] .AxisX.Interval = 1 the distance between the X-axis data of a racket.

Chart1.ChartAreas ["ChartArea1"] .AxisX.MajorGrid.Enabled = false;// does not show vertical split lines

Chart1.Series [0] .IsValueShownAsLabel = true;// display coordinate values

# endregion

}

Protected void GetStyle2 (DataTable dt)

{

# region Spline (smooth Curve)

Chart2.DataSource = dt;// bind data

Chart2.Series ["Series1"] .ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Spline;// sets the chart type

Chart2.Series ["Series1"] .MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Cross;// set the style of the point, cross

Chart2.Series [0] .XValueMember = "Country"; / / X axis data member column

Chart2.Series [0] .YValueMembers = "Score"; / / Y axis data member column

Chart2.ChartAreas ["ChartArea1"] .AxisX.Title = "country"; / / X axis title

Chart2.ChartAreas ["ChartArea1"] .AxisX.TitleAlignment = StringAlignment.Far;// sets the name of the Y-axis title in a position far away

Chart2.ChartAreas ["ChartArea1"] .AxisY.Title = "Gold"; / / X axis title

Chart2.ChartAreas ["ChartArea1"] .AxisY.TitleAlignment = StringAlignment.Far;// sets the name of the Y-axis title in a position far away

Chart2.ChartAreas ["ChartArea1"] .AxisX.Interval = 1 the distance between the X-axis data of a racket.

Chart2.ChartAreas ["ChartArea1"] .AxisX.MajorGrid.Enabled = false;// does not show vertical split lines

Chart2.Series [0] .IsValueShownAsLabel = true;// display coordinate values

# endregion

}

Protected void GetStyle3 (DataTable dt)

{

# region bar chart

Chart3.DataSource = dt;// bind data

Chart3.Series ["Series1"] .ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;// sets the chart type

Chart3.Series [0] .XValueMember = "Country"; / / X axis data member column

Chart3.Series [0] .YValueMembers = "Score"; / / Y axis data member column

Chart3.ChartAreas ["ChartArea1"] .AxisX.Title = "country"; / / X axis title

Chart3.ChartAreas ["ChartArea1"] .AxisX.TitleAlignment = StringAlignment.Far;// sets the name of the Y-axis title in a position far away

Chart3.ChartAreas ["ChartArea1"] .AxisY.Title = "Gold"; / / X axis title

Chart3.ChartAreas ["ChartArea1"] .AxisY.TitleAlignment = StringAlignment.Far;// sets the name of the Y-axis title in a position far away

Chart3.ChartAreas ["ChartArea1"] .AxisX.Interval = 1 the distance between the X-axis data of a racket.

Chart3.ChartAreas ["ChartArea1"] .AxisX.MajorGrid.Enabled = false;// does not show vertical split lines

Chart3.Series [0] .IsValueShownAsLabel = true;// display coordinate values

# endregion

}

Protected void GetStyle4 (DataTable dt)

{

# region pie chart

Chart4.DataSource = dt;// bind data

Chart4.Series ["Series1"] .ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;// sets the chart type

Chart4.Series [0] .XValueMember = "Country"; / / X axis data member column

Chart4.Series [0] .YValueMembers = "Score"; / / Y axis data member column

Chart4.Series [0] .LegendMapAreaAttributes = "Country"; / / Show country

Chart4.Series [0] .IsValueShownAsLabel = true;// display coordinate values

# endregion

}

/ / /

/ / create a two-dimensional data table

/ / /

/ / data table of type Datatable

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 [] {"China", "US", "Russia", "UK"}

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

This is the end of "how to use asp.net Microsoft Chart Control". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Data title member chart code location name location type country standard value control split line gold medal spacing Microsoft content datasheet more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Information Microsoft macOS NVidia