Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9703

cscの作法 その70

$
0
0
概要 cscの作法、調べてみた。 mdbにsql投げて合計求めて、円グラフにしてみた。 参考にしたページ 写真 コンパイル手順 >set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH% >csc pie0.cs /platform:x86 /r:System.Windows.Forms.DataVisualization.dll サンプルコード using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using System.Data.OleDb; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { ClientSize = new Size(900, 600); var chart1 = new Chart { Dock = DockStyle.Fill, }; this.Controls.Add(chart1); Series mySeries = new Series("series"); int[] data = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; string[] moku = new string[] { "光熱・水道", "家具・家事用品", "教養娯楽", "住居", "保健医療", "交通・通信", "交際費", "非消費支出(直接税・社会保険料)", "食料", "被服及び履物", "雑費", "貯蓄" }; OleDbConnection con = new OleDbConnection(); con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.mdb;"; con.Open(); for (int i = 0; i < 11; i++) { string sSQL = "SELECT SUM(金額) FROM sisyutu WHERE 項目 = '" + moku[i] + "'"; OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sSQL, con); object sum = cmd.ExecuteScalar(); if (sum != DBNull.Value) { int k = Convert.ToInt32(sum); Console.WriteLine(k); data[i] = k; } } mySeries.Points.DataBindXY(moku, data); mySeries.ChartType = SeriesChartType.Pie; mySeries["PieLabelStyle"] = "Inside"; mySeries["PieDrawingStyle"] = "Default"; ChartArea myArea = new ChartArea("area"); chart1.ChartAreas.Add("area"); chart1.Series.Add(mySeries); mySeries.ChartArea = "area"; chart1.Legends.Add(new Legend("Default")); LegendCellColumn firstColumn = new LegendCellColumn(); firstColumn.ColumnType = LegendCellColumnType.SeriesSymbol; firstColumn.HeaderText = ""; chart1.Legends["Default"].CellColumns.Add(firstColumn); LegendCellColumn percentColumn = new LegendCellColumn(); percentColumn.Text = "#PERCENT"; percentColumn.HeaderText = "Percentage"; percentColumn.Name = "nameColumn"; chart1.Legends["Default"].CellColumns.Add(percentColumn); chart1.Legends["Default"].LegendStyle = LegendStyle.Table; chart1.Legends["Default"].TableStyle = LegendTableStyle.Tall; chart1.Legends["Default"].DockedToChartArea = "area"; chart1.Legends["Default"].IsDockedInsideChartArea = false; chart1.Legends["Default"].Docking = Docking.Right; } [STAThread] static void Main() { Application.Run(new Form1()); } } } 以上。

Viewing all articles
Browse latest Browse all 9703

Trending Articles