public void Add(int count, string name) { DoughnutData doughnutData = new DoughnutData { Name = $"'{name}'", Value = count, Color = $"'{_colors[_colourIndex++]}'" }; if (_colourIndex == _colors.Count) { _colourIndex = 0; } _doughnutDatas.Add(doughnutData); }
/// データの設定 private DataSet GetData(DoughnutData datas) { DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dtRow; // 列の作成 dt.Columns.Add("項目", Type.GetType("System.String")); dt.Columns.Add("項目別合計費", Type.GetType("System.Int32")); ds.Tables.Add(dt); for (int i = 0; i < datas.item.Length; i++) { // データの追加 dtRow = ds.Tables[0].NewRow(); dtRow[0] = datas.item[i]; dtRow[1] = datas.item_total_cost[i]; ds.Tables[0].Rows.Add(dtRow); } return(ds); }
private void updateDoughnutGraph() { DoughnutData datas = new DoughnutData() { item = new string[dataGridView1.Rows.Count], item_total_cost = new int[dataGridView1.Rows.Count] }; getEachItemTotalCost(ref datas.item, ref datas.item_total_cost); // 初期化 chart1.Series.Clear(); chart1.Titles.Clear(); // データの取得 DataSet ds = GetData(datas); // Chartコントロールにデータソースを設定 chart1.DataSource = ds; // Chartコントロールにタイトルを設定 chart1.Titles.Add("項目別の割合"); // グラフの種類,系列,軸の設定 for (int i = 1; i < ds.Tables[0].Columns.Count; i++) { // 列名の取得 string columnName = ds.Tables[0].Columns[i].ColumnName; // 系列の設定 chart1.Series.Add(columnName); // グラフの種類 chart1.Series[columnName].ChartType = SeriesChartType.Doughnut; // X軸 chart1.Series[columnName].XValueMember = ds.Tables[0].Columns[0].ColumnName.ToString(); chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false; chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = false; // Y軸 chart1.Series[columnName].YValueMembers = columnName; } // X軸タイトル chart1.ChartAreas[0].AxisX.Title = "項目"; chart1.DataBind(); /* * // フォームをロードするときの処理 * chart1.Series.Clear(); // ← 最初からSeriesが1つあるのでクリアします * chart1.ChartAreas.Clear(); * * // ChartにChartAreaを追加します * string chart_area1 = "Area1"; * chart1.ChartAreas.Add(new ChartArea(chart_area1)); * // ChartにSeriesを追加します * string legend1 = "Graph1"; * chart1.Series.Add(legend1); * // グラフの種別を指定 * chart1.Series[legend1].ChartType = SeriesChartType.Pie; // 円グラフを指定してみます * * // 各項目の値を加算して合計(全体の大きさ)を算出します * double total = (double)datas.item_total_cost.Sum(); * * // データをシリーズにセットします * for (int i = 0; i < datas.item_total_cost.Length; i++) * { * double rate = (datas.item_total_cost[i] / total) * 100.0; // <-- ここで割合を算出します * DataPoint dp = new DataPoint(rate, rate); * chart1.Series[legend1].Points.Add(dp); * } */ }
public ViewModel() { this.Data = new List <Model>(); Data.Add(new Model() { Country = "Uruguay", Count = 2807 }); Data.Add(new Model() { Country = "Argentina", Count = 2577 }); Data.Add(new Model() { Country = "USA", Count = 960 }); Data.Add(new Model() { Country = "Germany", Count = 2120 }); this.DoughnutData = new List <Model>(); DoughnutData.Add(new Model() { Country = "USA", Count = 2473 }); DoughnutData.Add(new Model() { Country = "Germany", Count = 2120 }); DoughnutData.Add(new Model() { Country = "Malta", Count = 960 }); DoughnutData.Add(new Model() { Country = "Maldives", Count = 941 }); this.SemiPieData = new List <Model>(); SemiPieData.Add(new Model() { Country = "USA", Count = 473 }); SemiPieData.Add(new Model() { Country = "Germany", Count = 1120 }); SemiPieData.Add(new Model() { Country = "Malta", Count = 960 }); SemiPieData.Add(new Model() { Country = "Monaco", Count = 908 }); this.Collection = new List <Model>(); Collection.Add(new Model() { Name = "Week1", Count = 45 }); Collection.Add(new Model() { Name = "Week2", Count = 60 }); Collection.Add(new Model() { Name = "Week3", Count = 70 }); Collection.Add(new Model() { Name = "Week4", Count = 85 }); this.Population = new List <Populations>(); Population.Add(new Populations() { Continent = "Asia", Countries = "China", States = "Taiwan", PopulationinContinents = 50.02, PopulationinCountries = 26.02, PopulationinStates = 18.02 }); Population.Add(new Populations() { Continent = "Africa", Countries = "India", States = "Shandong", PopulationinContinents = 20.81, PopulationinCountries = 24, PopulationinStates = 8 }); Population.Add(new Populations() { Continent = "Europe", Countries = "Nigeria", States = "UP", PopulationinContinents = 15.37, PopulationinCountries = 12.81, PopulationinStates = 14.5 }); Population.Add(new Populations() { Countries = "Ethiopia", States = "Maharashtra", PopulationinCountries = 8, PopulationinStates = 9.5 }); Population.Add(new Populations() { Countries = "Germany", States = "Kano", PopulationinCountries = 8.37, PopulationinStates = 7.81 }); Population.Add(new Populations() { Countries = "Turkey", States = "Lagos", PopulationinCountries = 7, PopulationinStates = 5 }); Population.Add(new Populations() { States = "Oromia", PopulationinStates = 5 }); Population.Add(new Populations() { States = "Amhara", PopulationinStates = 3 }); Population.Add(new Populations() { States = "Hessen", PopulationinStates = 5.37 }); Population.Add(new Populations() { States = "Bayern", PopulationinStates = 3 }); Population.Add(new Populations() { States = "Istanbul", PopulationinStates = 4.5 }); Population.Add(new Populations() { States = "Ankara", PopulationinStates = 2.5 }); }