private void draw()
{
SeriesList sList = new SeriesList();
sList.ChartType = ChartType.Scatter;
Random r = new Random();
for(int i = 0; i < 1; i++)
{
Series sr = new Series();
sr.Points.Width = 4;
sr.Points.PointType = PointType.FillCircle;
for(int x = 0; x < 150; x++)
{
SeriesItem item = new SeriesItem();
item.XValue = x;
item.YValue = r.Next(500) * x + 13;
sr.items.Add(item);
}
sList.SeriesCollection.Add(sr);
}
sList.SeriesCollection.Add(this.GetTrendSeries(sList));
this.hHippoChart2.LegendBox.Visible = false;
this.hHippoChart2.Titles.Label.ForeColor = Color.SteelBlue;
this.hHippoChart2.DesignType = ChartDesignType.Simple;
this.hHippoChart2.SeriesListDictionary.Add(sList);
this.hHippoChart2.DrawChart();
}
private Series GetTrendSeries(SeriesList sList)
{
Series TrSr = new Series();
TrSr.SeriesColor = Color.Blue;
TrSr.ChartType = ChartType.Line;
double a = 0;
double b = 0;
double[,] MatrixL = new double[2, 2];
double[,] InverseMatrixL = new double[2, 2];
double[] MatrixR = new double[2];
int totalcount = 0;
foreach(Series sr in sList.SeriesCollection)
{
foreach(SeriesItem item in sr.items)
{
MatrixL[0, 0] = MatrixL[0, 0] + 1;
MatrixL[1, 0] += item.XValue * 1;
MatrixL[0, 1] += item.XValue * 1;
MatrixL[1, 1] += item.XValue * item.XValue;
MatrixR[0] += item.YValue * 1;
MatrixR[1] += item.YValue * item.XValue;
totalcount++;
}
}
// 역행렬을 만드는 공식에서 ad - bc 체크
double adMinusbc = MatrixL[0, 0] * MatrixL[1, 1] - MatrixL[1, 0] * MatrixL[0, 1];
if (adMinusbc != 0)
{
InverseMatrixL[0, 0] = MatrixL[1, 1] / adMinusbc;
InverseMatrixL[1, 0] = (MatrixL[1, 0] * (-1)) / adMinusbc;
InverseMatrixL[0, 1] = (MatrixL[0, 1] * (-1)) / adMinusbc;
InverseMatrixL[1, 1] = MatrixL[0, 0] / adMinusbc;
a = (InverseMatrixL[0, 0] * MatrixR[0] + InverseMatrixL[1, 0] * MatrixR[1]);
b = (InverseMatrixL[0, 1] * MatrixR[0] + InverseMatrixL[1, 1] * MatrixR[1]);
// 해당 시리즈 만들기
for(int i = 0; i < totalcount; i++)
{
SeriesItem tritem = new SeriesItem();
tritem.XValue = i;
tritem.YValue = (float)(b * i + a);
TrSr.items.Add(tritem);
}
}
else // 나누는 분모가 0이 되므로 불능
{
// 해당 시리즈 만들기
for(int i = 0; i < totalcount; i++)
{
SeriesItem tritem = new SeriesItem();
tritem.XValue = i;
tritem.YValue = 0;
TrSr.items.Add(tritem);
}
}
return TrSr;
}
Private Sub draw()
Dim sList As New. SeriesList()
sList.ChartType = ChartType.Scatter
Dim r As New. Random()
Dim i As Integer = 0
While i < 1
Dim sr As New. Series()
sr.Points.Width = 4
sr.Points.PointType = PointType.FillCircle
Dim x As Integer = 0
While x < 150
Dim item As New. SeriesItem()
item.XValue = x
item.YValue = r.[Next](500) * x + 13
sr.items.Add(item)
System.Math.Max(System.Threading.Interlocked.Increment(x),x - 1)
End While
sList.SeriesCollection.Add(sr)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
sList.SeriesCollection.Add(Me.GetTrendSeries(sList))
Me.hHippoChart2.LegendBox.Visible = False
Me.hHippoChart2.Titles.Label.ForeColor = Color.SteelBlue
Me.hHippoChart2.DesignType = ChartDesignType.Simple
Me.hHippoChart2.SeriesListDictionary.Add(sList)
Me.hHippoChart2.DrawChart()
End Sub
Private Function GetTrendSeries(sList As SeriesList) As Series
Dim TrSr As New. Series()
TrSr.SeriesColor = Color.Blue
TrSr.ChartType = ChartType.Line
Dim a As Double = 0
Dim b As Double = 0
Dim MatrixL As Double(,) = New Double(2, 2) {}
Dim InverseMatrixL As Double(,) = New Double(2, 2) {}
Dim MatrixR As Double() = New Double(2) {}
Dim totalcount As Integer = 0
For Each sr As Series In sList.SeriesCollection
For Each item As SeriesItem In sr.items
MatrixL(0, 0) = MatrixL(0, 0) + 1
MatrixL(1, 0) += item.XValue * 1
MatrixL(0, 1) += item.XValue * 1
MatrixL(1, 1) += item.XValue * item.XValue
MatrixR(0) += item.YValue * 1
MatrixR(1) += item.YValue * item.XValue
System.Math.Max(System.Threading.Interlocked.Increment(totalcount),totalcount - 1)
Next
Next
` 역행렬을 만드는 공식에서 ad - bc 체크
Dim adMinusbc As Double = MatrixL(0, 0) * MatrixL(1, 1) - MatrixL(1, 0) * MatrixL(0, 1)
If adMinusbc <> 0 Then
InverseMatrixL(0, 0) = MatrixL(1, 1) / adMinusbc
InverseMatrixL(1, 0) = (MatrixL(1, 0) * (-1)) / adMinusbc
InverseMatrixL(0, 1) = (MatrixL(0, 1) * (-1)) / adMinusbc
InverseMatrixL(1, 1) = MatrixL(0, 0) / adMinusbc
a = (InverseMatrixL(0, 0) * MatrixR(0) + InverseMatrixL(1, 0) * MatrixR(1))
b = (InverseMatrixL(0, 1) * MatrixR(0) + InverseMatrixL(1, 1) * MatrixR(1))
` 해당 시리즈 만들기
Dim i As Integer = 0
While i < totalcount
Dim tritem As New. SeriesItem()
tritem.XValue = i
tritem.YValue = DirectCast((b * i + a), Single)
TrSr.items.Add(tritem)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Else
` 나누는 분모가 0이 되므로 불능
` 해당 시리즈 만들기
Dim i As Integer = 0
While i < totalcount
Dim tritem As New. SeriesItem()
tritem.XValue = i
tritem.YValue = 0
TrSr.items.Add(tritem)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
End If
Return TrSr
End Function