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