ASP.NET 円グラフ
メモ
Imports System.Data.SqlClient Public Class Graph5 Inherits System.Web.UI.Page Dim con As New SqlConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click con.ConnectionString = ConfigurationManager.ConnectionStrings("OrderConnectionString").ConnectionString Dim strSQL As String = "SELECT" strSQL += " Shop, Value" strSQL += " FROM sampleDB2.dbo.Graph04" strSQL += " WHERE Year = @pYear" strSQL += " AND Month = @pMonth" strSQL += " ORDER BY Value DESC" Dim cmd As New SqlCommand(strSQL, con) Dim pYear As SqlParameter = cmd.Parameters.Add("@pYear", System.Data.SqlDbType.Int) pYear.Value = 2017 Dim pMonth As SqlParameter = cmd.Parameters.Add("@pMonth", System.Data.SqlDbType.TinyInt) pMonth.Value = 1 con.Open() Dim dAdap As New SqlDataAdapter() dAdap.SelectCommand = cmd Dim ds As New DataSet dAdap.Fill(ds) con.Close() con.Dispose() With Chart1 '初期化 .Series.Clear() 'Chartコントロールにデータソースを設定 .DataSource = ds 'Chartコントロールにタイトルを設定 .Titles.Add("ドーナッツのサンプル") '系列の設定 .Series.Add("Doughnut") 'グラフの種類 .Series("Doughnut").ChartType = DataVisualization.Charting.SeriesChartType.Doughnut '円弧の開始角度 .Series("Doughnut").CustomProperties = "PieStartAngle=270,DoughnutRadius=70" 'X軸 .Series("Doughnut").XValueMember() = "Shop" 'Y軸 .Series("Doughnut").YValueMembers = "Value" 'ラベルに値を表示 .Series("Doughnut").Label = "#PERCENT{#0.0%}" '項目名 #VALX %表示 #PERCENT{#0.0%} #PERCENT{P1}でもOK 'Chart1.Series("Doughnut").Label = "#VALX #PERCENT{#0.0%}" '項目名 #VALX 値 #VALY '凡例 .Series("Doughnut").LegendText = "#VALX #VALY" .Legends.Add("Legends") .Legends("Legends").Docking = DataVisualization.Charting.Docking.Right .DataBind() End With End Sub End Class
参考URL
http://www.atmarkit.co.jp/fdotnet/dotnettips/1001aspchartpie/aspchartpie.html
http://www.oborodukiyo.info/MSChart/VS2008/MSC-CustomPropertyAtPieGraph.aspx
http://www.atmarkit.co.jp/fdotnet/dotnettips/1002aspchartlegend/aspchartlegend.html
https://social.msdn.microsoft.com/Forums/vstudio/ja-JP/996de6ba-d395-44d9-b382-4746583aca04/-?forum=aspnetja
http://c1.grapecity.com/help/web/aspnet/webchart/displayingthedatalab.html