■ LegendPalette 클래스를 사용해 레전드 팔레트를 만드는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
using System; using System.Drawing; using System.Windows.Forms; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; using Steema.TeeChart.Tools; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// X 카운트 /// </summary> private const int X_COUNT = 30; /// <summary> /// Z 카운트 /// </summary> private const int Z_COUNT = 30; /// <summary> /// 표면 /// </summary> private Surface surface; /// <summary> /// 레전트 팔레트 /// </summary> private LegendPalette legendPalette; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.verticalCheckBox.Checked = true; this.transparentCheckBox.Checked = true; this.axisComboBox.DropDownStyle = ComboBoxStyle.DropDownList; this.axisComboBox.Items.Add("Default"); this.axisComboBox.Items.Add("Other" ); this.axisComboBox.Items.Add("Both" ); this.axisComboBox.SelectedIndex = 0; Text = "LegendPalette 클래스 : 레전트 팔레트 사용하기"; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.tChart.Legend.Visible = false; this.surface = new Surface(this.tChart.Chart); this.surface.UsePalette = false; this.surface.UseColorRange = true; this.surface.NumXValues = X_COUNT; this.surface.NumZValues = Z_COUNT; for(int x = 1; x <= X_COUNT; x++) { for(int z = 1; z <= Z_COUNT; z++) { this.surface.Add ( x, Math.Cos(0.14 * x) * Math.Cos(0.25 * z) + 0.01 * (x - (X_COUNT / 2)) * (z - (Z_COUNT / 2)) + 13.0 * Math.Exp(-0.06 * (Math.Pow(x - (X_COUNT / 2), 2) + Math.Pow(z - (Z_COUNT / 2), 2))) + 6 * Math.Exp(-0.03 * (Math.Pow(x - (X_COUNT / 3), 2) + Math.Pow(z - 3 * (Z_COUNT / 5), 2))) - 1, z ); } } this.legendPalette = new LegendPalette(this.tChart.Chart); this.legendPalette.Left = this.tChart.Width - this.legendPalette.Width - 10; this.legendPalette.Vertical = true; this.legendPalette.Transparent = true; this.legendPalette.Pen.Visible = false; this.legendPalette.Series = this.surface; this.verticalCheckBox.CheckedChanged += verticalCheckBox_CheckedChanged; this.transparentCheckBox.CheckedChanged += transparentCheckBox_CheckedChanged; this.axisComboBox.SelectedIndexChanged += axisComboBox_SelectedIndexChanged; this.penCheckBox.CheckedChanged += penCheckBox_CheckedChanged; this.tChart.Resize += tChart_Resize; this.tChart.Refresh(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 수직 체크 박스 체크 변경시 처리하기 - verticalCheckBox_CheckedChanged(sender, e) /// <summary> /// 수직 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void verticalCheckBox_CheckedChanged(object sender, EventArgs e) { this.legendPalette.Vertical = this.verticalCheckBox.Checked; this.legendPalette.Left = this.tChart.Width - this.legendPalette.Width - 10; } #endregion #region 투명 체크 박스 체크 변경시 처리하기 - transparentCheckBox_CheckedChanged(sender, e) /// <summary> /// 투명 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void transparentCheckBox_CheckedChanged(object sender, EventArgs e) { this.legendPalette.Transparent = this.transparentCheckBox.Checked; this.tChart.Refresh(); } #endregion #region 축 콤보 박스 선택 인덱스 변경시 처리하기 - axisComboBox_SelectedIndexChanged(sender, e) /// <summary> /// 축 콤보 박스 선택 인덱스 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void axisComboBox_SelectedIndexChanged(object sender, EventArgs e) { this.legendPalette.Axis = (LegendPaletteAxis)this.axisComboBox.SelectedIndex; } #endregion #region 펜 체크 박스 체크 변경시 처리하기 - penCheckBox_CheckedChanged(sender, e) /// <summary> /// 펜 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void penCheckBox_CheckedChanged(object sender, EventArgs e) { this.legendPalette.Pen.Visible = this.penCheckBox.Checked; this.tChart.Refresh(); } #endregion #region TChart 크기 변경시 처리하기 - tChart_Resize(sender, e) /// <summary> /// TChart 크기 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_Resize(object sender, EventArgs e) { this.legendPalette.Left = this.tChart.Width - this.legendPalette.Width - 10; } #endregion } } |