먼저 툴박스에서 차트를 드래그 앤 드롭으로 디자인 한 후..
속성에서 여러가지 설정을 미리 해 두는 것이 편하다.
여기를 클릭해서 들어가면 여러가지 설정이 가능한데, 사실 코드로도 설정할 수 있음.
편한대로 ㅋㅋ (역시 GUI가 좋긴 하지만 코드로는 수동으로 세부조절 및 표시가 가능)
그래프 타입이나 Series(데이터가 들어감), 타이틀 등 여러가지 설정이 가능.
그리고 ChartArea 설정에서 3D 로 표시가능. 여기서는 Area3DStyle을 true로 설정했음.
하고싶은 건 유저컨트롤이 로딩될 때 객체에 있는 4개의 점수를 파이 그래프로 표시한 후, 가장 큰 값을 가지는 부분을 따로 떼어내서 강조하는 것이다. 다음과 같이 코드를 작성했음.
private void home_uc_form_Load(object sender, EventArgs e)
{
// 그래프 작성 : 홈 유저컨트롤이 로드되면 그래프를 표시함
// 그래프 배경을 투명으로 설정
chart1.BackColor = Color.Transparent;
chart1.BackSecondaryColor = Color.Transparent;
//chart1에 값을 대입함, 여기서는 member객체에 각 체질별 점수가 있다고 가정함.
chart1.Series["Series1"].Points.AddXY("Dry", member.DryScore);
chart1.Series["Series1"].Points.AddXY("Hot", member.HotScore);
chart1.Series["Series1"].Points.AddXY("Humid", member.HumidScore);
chart1.Series["Series1"].Points.AddXY("Cold", member.ColdScore);
//차트에 값을 표시할 때 퍼센트로 표시하게 라벨변경
chart1.Series["Series1"].Points[0].Label = "#PERCENT{P0}";
chart1.Series["Series1"].Points[1].Label = "#PERCENT{P0}";
chart1.Series["Series1"].Points[2].Label = "#PERCENT{P0}";
chart1.Series["Series1"].Points[3].Label = "#PERCENT{P0}";
//색상설정 (체질별로 대표색상이 있으므로 색상을 지정함)
chart1.Series["Series1"].Points[0].Color = Color.Gold;
chart1.Series["Series1"].Points[1].Color = Color.Red;
chart1.Series["Series1"].Points[2].Color = Color.Green;
chart1.Series["Series1"].Points[3].Color = Color.DodgerBlue;
// 범례, 그래프 밑에 표시하고 가운데 정렬을 함.
chart1.Series[0].Points[0].LegendText = "Dry";
chart1.Series[0].Points[1].LegendText = "Hot";
chart1.Series[0].Points[2].LegendText = "Humid";
chart1.Series[0].Points[3].LegendText = "Cold";
chart1.Series[0].IsVisibleInLegend = true;
chart1.Legends[0].Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Bottom;
chart1.Legends[0].Alignment = StringAlignment.Center;
// 차트를 갱신하고 싶은 경우
// chart1.Invalidate();
// 각 체질별로 표시할 때 그래프를 잘라서 강조하고 싶은 경우
switch (member.TypeId)
{
case 1:
lb_type.Text = "あなたは、\n Dry(乾)タイプです。";
chart1.Series[0].Points[0]["Exploded"] = "true";
break;
case 2:
lb_type.Text = "あなたは、\n Hot(熱)タイプです。";
chart1.Series[0].Points[1]["Exploded"] = "true";
break;
case 3:
lb_type.Text = "あなたは、\n Humid(湿)タイプです。";
chart1.Series[0].Points[2]["Exploded"] = "true";
break;
case 4:
lb_type.Text = "あなたは、\n Cold(冷)タイプです。";
chart1.Series[0].Points[3]["Exploded"] = "true";
break;
default:
lb_type.Text = "(体質診断未実施)";
chart1.Series[0]["CollectedSliceExploded"] = "false";
break;
}
}
결과적으로 다음과 같은 그래프가 표시됨.
댓글
댓글 쓰기