■ Line 클래스의 Function 속성을 사용해 커스텀 함수를 설정하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 |
using System; using Steema.TeeChart; using Steema.TeeChart.Styles; /// <summary> /// 제곱근 합계 /// </summary> public class SquareRootSummary : Function { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - SquareRootSummary() /// <summary> /// 생성자 /// </summary> public SquareRootSummary(): base() { } #endregion #region 생성자 - SquareRootSummary(innerChart) /// <summary> /// 생성자 /// </summary> /// <param name="innerChart">내부 Chart</param> public SquareRootSummary(Chart innerChart) : base(innerChart) { } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 계산하기 - Calculate(sourceSeries, firstIndex, lastIndex) /// <summary> /// 계산하기 /// </summary> /// <param name="sourceSeries">소스 시리즈</param> /// <param name="firstIndex">첫번째 인덱스</param> /// <param name="lastIndex">마지막 인덱스</param> /// <returns>계산 값</returns> public override double Calculate(Series sourceSeries, int firstIndex, int lastIndex) { ValueList valueList = ValueList(sourceSeries); if(firstIndex == -1) { double result = 0d; for(int i = 0; i < sourceSeries.Count; i++) { result += Math.Sqrt(valueList[i]); } return result; } else { double result = 0d; for(int i = firstIndex; i <= lastIndex; i++) { result += Math.Sqrt(valueList[i]); } return result; } } #endregion #region 다수 계산하기 - CalculateMany(sourceSeriesArrayList, valueIndex) /// <summary> /// 다수 계산하기 /// </summary> /// <param name="sourceSeriesArrayList">소스 시리즈 배열 리스트</param> /// <param name="valueIndex">값 인덱스</param> /// <returns>계산 값</returns> public override double CalculateMany(ArrayList sourceSeriesArrayList, int valueIndex) { ValueList valueList = null; double result = 0d; for(int i = 0; i < sourceSeriesArrayList.Count; i++) { valueList = ValueList(sourceSeriesArrayList[i] as Series); if(valueList.Count > valueIndex) { result += Math.Sqrt(valueList[valueIndex]); } } return result; } #endregion } ... #region 차트를 생성한다. TChart chart = new TChart(); chart.Aspect.View3D = false; #endregion #region 막대 시리즈를 생성한다. Bar bar = new Bar(); bar.FillSampleValues(); chart.Series.Add(bar); #endregion #region 커스텀 함수를 생성한다. SquareRootSummary squareSummary = new SquareRootSummary(); #endregion #region 라인 시리즈를 생성한다. Line line = new Line(); line.LinePen.Width = 3; line.DataSource = bar; line.Function = squareSummary; line.Color = Color.Red; line.CheckDataSource(); chart.Series.Add(line); #endregion |