■ TChart 클래스에서 레전드 아래에 추가 텍스트를 표시하는 방법을 보여준다.
▶ 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 |
using System.Drawing; using System.Windows.Forms; using Steema.TeeChart; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "TChart 클래스 : 레전드 아래에 추가 텍스트 표시하기"; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.tChart.Legend.LegendStyle = LegendStyles.Auto; Bar bar = new Bar(this.tChart.Chart); bar.FillSampleValues(6); bar.Labels[0] = "one"; bar.Labels[1] = "two"; bar.Labels[2] = "three"; bar.Labels[3] = "four"; bar.Labels[4] = "five"; bar.Labels[5] = "six"; this.tChart.GetLegendPos += tChart_GetLegendPos; this.tChart.GetLegendRect += tChart_GetLegendRect; this.tChart.AfterDraw += tChart_AfterDraw; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region TChart 레전드 위치 구하기 - tChart_GetLegendPos(sender, e) /// <summary> /// TChart 레전드 위치 구하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_GetLegendPos(object sender, GetLegendPosEventArgs e) { e.X -= 40; e.XColor -= 40; } #endregion #region TChart 레전드 사각형 구하기 - tChart_GetLegendRect(sender, e) /// <summary> /// TChart 레전드 사각형 구하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_GetLegendRect(object sender, GetLegendRectEventArgs e) { e.Rectangle = new Rectangle ( e.Rectangle.Left - 40, e.Rectangle.Top, e.Rectangle.Width + 10, e.Rectangle.Height + 30 ); } #endregion #region TChart 그리기 후 처리하기 - tChart_AfterDraw(sender, graphics3D) /// <summary> /// TChart 그리기 후 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="graphics3D">그래픽스 3D</param> private void tChart_AfterDraw(object sender, Graphics3D graphics3D) { TChart tChart = sender as TChart; Rectangle legendRectangle = tChart.Legend.ShapeBounds; graphics3D.HorizontalLine(legendRectangle.Left, legendRectangle.Right, legendRectangle.Bottom - 30); graphics3D.TextAlign = StringAlignment.Near; graphics3D.Font.Size = 8; graphics3D.Font.Color = Color.Navy; graphics3D.TextOut(legendRectangle.Left + 8, legendRectangle.Bottom - 28, "Additional text"); graphics3D.TextOut(legendRectangle.Left + 8, legendRectangle.Bottom - 16, "displayed here."); } #endregion } } |