0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

cscの作法 その71 積み上げ縦棒グラフ

Posted at

概要

cscの作法、調べてみた。
積み上げ縦棒グラフやってみた。

写真

image.png

コンパイル手順

>set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%

>csc ch4.cs /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;

namespace WindowsFormsApplication1
{
	public partial class Form1 : Form {
		public Form1() {
			var chart1 = new Chart {
				Dock = DockStyle.Fill,
			};
			this.Controls.Add(chart1);
			string[] legends = new string[] { "グラフ1", "グラフ2" };
			string[] xValues = new string[] { "A", "B", "C", "D", "E" };
			int[,] yValues = new int[,] {{ 10, 20, 30, 40, 50 }, {20, 40, 60, 80, 100}};
			chart1.Series.Clear();
			chart1.ChartAreas.Clear();
			chart1.Titles.Clear();
			foreach (var item in legends)
			{
				chart1.Series.Add(item);
				chart1.Series[item].ChartType = SeriesChartType.StackedColumn;
				chart1.Series[item].LegendText = item;
			}
			for (int i = 0; i < xValues.Length; i++)
			{
				for (int j = 0; j < yValues.GetLength(0); j++)
				{
					DataPoint dp = new DataPoint();
					dp.SetValueXY(xValues[i], yValues[j, i]);
					dp.IsValueShownAsLabel = true;
					chart1.Series[legends[j]].Points.Add(dp);
				}
			}
			ChartArea area1 = new ChartArea();
			area1.AxisX.Title = "Title-XAxis";
			area1.AxisY.Title = "Title-YAxis";
			Title title1 = new Title("Title1");
			chart1.Titles.Add(title1);
			chart1.ChartAreas.Add(area1);
			Legend legend = new Legend();
			chart1.Legends.Add(legend);
			legend.Docking = Docking.Top;
		}
		[STAThread]
		static void Main() {
			Application.Run(new Form1());
		}
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?