Home 소개       다운로드       온라인 설명서      주식/코인 차트    Q & A     Blog    

히포차트 4.1 - 주식 차트 활용 (틱 배경색), Area라인 차트







실제 주식 차트에 활용할 수 있는 샘플 코드입니다.

- 영역형 라인 차트 추가
- 틱 배경색 기능으로 현재가 표시
- 추세선
- 축 오른쪽으로 만드는 방법(팁)




Candle chart  Candle chart2  주식 캔들 차트 - 최고가, 최저가, 특정 봉 정보  히포차트 4.1 - 주식 차트 활용 (틱 배경색), Area라인 차트  히포차트 4.3 - 주식 봉 차트 HTS 프로그램 개발하기  키움증권 OpenAPI 로 제작된 실시간 주식 차트 프로그램  [히포차트 4.3] - 주식 캔들 차트 보조지표 일목균형표  히포차트 4.3 - 주식차트 20일 이동평균선 그리기  히포차트 4.3 - 주식차트 보조지표 MACD, 시그널, 오실레이터, 지수이동평균선  히포차트 4.3 - 주식차트 보조지표 볼린저밴드(Bollinger Band) 그리기  히포차트 4.3 - 스토캐스틱(Stochastics) 주식차트 보조지표  히포차트 4.3 - 주식 차트 보조지표 RSI 공식적용 그래프  


C#
 
HippoEngine en = new HippoEngine();
en.DataType = DataSourceType.Excel;
en.Query = "select * from [Sheet1$]";
en.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`C:\Users\neohippo\Dropbox\Projects\_Hippochart\Hippo 4.1\Hippo Chart 2010 4\HippoChartBeta\WindowsHippoTest\주식차트샘플2.xls`;Extended Properties=`Excel 12.0;HDR=YES`";

SeriesList sList = en.GetSeriesListOfStock(DataSourceType.Excel, "년/월", "시가", "종가", "저가", "고가");

sList.AxisFactor.AxisItems.Add(new Axis(AxisType.Ytype));
sList.AxisFactor.AxisItems[0].SetAxisStep(10000, 40000, 5000);

sList.AxisFactor.YAxis.Visible = false;

sList.ChartType = ChartType.CandleStick;
sList.SeriesCollection[0].Name = "주가 ";
sList.GraphArea.Grid.Interval = 10;
sList.AxisFactor.XAxis.Interval = 15;
sList.AxisFactor.YAxis.SetAxisStep(10000, 40000, 5000);

double tempMaxHighval = double.MinValue;
double tempMaxLowval = double.MaxValue;

SeriesItem Highitem = new SeriesItem();
SeriesItem Lowitem = new SeriesItem();

foreach(SeriesItem item in sList.SeriesCollection[0].items)
{
if (item.HighValue > tempMaxHighval)
{
tempMaxHighval = item.HighValue;
Highitem = item;
}

if (item.LowValue < tempMaxLowval)
{
tempMaxLowval = item.LowValue;
Lowitem = item;
}
}

if (Highitem != null)
{
Highitem.Balloon = new Balloon();
Highitem.Balloon.BalloonType = BalloonType.Rectangle;
Highitem.Balloon.HeightType = HeightType.Bottom;
Highitem.Balloon.BackColor = Color.Transparent;
Highitem.Balloon.Label.Text = "최고가 : " + Highitem.HighValue.ToString();
Highitem.Balloon.IsShadow = false;
Highitem.Balloon.Label.ForeColor = Color.Blue;
Highitem.Balloon.Line.LineColor = Color.Transparent;
}

if (Lowitem != null)
{
Lowitem.Balloon = new Balloon();
Lowitem.Balloon.BalloonType = BalloonType.Rectangle;
Lowitem.Balloon.HeightType = HeightType.Bottom;
Lowitem.Balloon.BackColor = Color.Transparent;
Lowitem.Balloon.Label.Text = "최저가 : " + Highitem.LowValue.ToString();
Lowitem.Balloon.IsShadow = false;
Lowitem.Balloon.Label.ForeColor = Color.Red;
Lowitem.Balloon.Line.LineColor = Color.Transparent;
}

sList.SeriesCollection[0].items[11].Balloon = new Balloon();
sList.SeriesCollection[0].items[11].Balloon.BalloonType = BalloonType.Rectangle;
sList.SeriesCollection[0].items[11].Balloon.BackColor = Color.White;
sList.SeriesCollection[0].items[11].Balloon.HeightType = HeightType.Bottom;
sList.SeriesCollection[0].items[11].Balloon.Label.Text = "유상증자 ( 0.00% )";

Series sr2 = new Series();
sr2.Name = "Trend1";
sr2.ChartType = ChartType.AreaLine;
sr2.Points.Width = 0;
sr2.Transparency = 99;
sr2.Line.LineWidth = 2;
sr2.SeriesColor = Color.Yellow;

Regression rg = new Regression();
rg.XYCount = sList.SeriesCollection[0].items.Count;
rg.Degree(4);

int count = 0;
foreach(SeriesItem item in sList.SeriesCollection[0].items)
{
rg.XYAdd(count, item.YValue);

count++;
}

for(int j = 0; j < 1000; j++)
{
rg.RegVal(j);
}

for(int i = 0; i < sList.SeriesCollection[0].items.Count; i++)
{
SeriesItem item2 = new SeriesItem();
item2.Name = sList.SeriesCollection[0].items[i].Name;
item2.YValue = rg.Coeff(4) * Math.Pow(i, 4) + rg.Coeff(3) * Math.Pow(i, 3) + rg.Coeff(2) * Math.Pow(i, 2) + rg.Coeff(1) * i + rg.Coeff(0);
item2.YStartValue = item2.YValue - 1500 * (new Random().Next(6));

sr2.items.Add(item2);
}

Series sr3 = new Series();
sr3.Name = "Trend2";
sr3.ChartType = ChartType.Line;
sr3.Line.LineWidth = 2;
sr3.Points.Width = 0;

rg = new Regression();
rg.XYCount = sList.SeriesCollection[0].items.Count;
rg.Degree(1);

count = 0;
foreach(SeriesItem item in sList.SeriesCollection[0].items)
{
rg.XYAdd(count, item.HighValue);

count++;
}

for(int j = 0; j < 1000; j++)
{
rg.RegVal(j);
}

for(int i = 0; i < sList.SeriesCollection[0].items.Count; i++)
{
SeriesItem item2 = new SeriesItem();

item2.Name = sList.SeriesCollection[0].items[i].Name;
item2.YValue = rg.Coeff(1) * i + rg.Coeff(0);

sr3.items.Add(item2);
}

sList.SeriesCollection.Add(sr2);
sList.SeriesCollection.Add(sr3);

sList.AxisFactor.AxisItems[0].Decimalpoint = 0;

AxisTick tk = new AxisTick(27670);
tk.Label.Font = new Font("굴림", 9, FontStyle.Regular);
tk.Label.Text = "25,670";
tk.BackColor = Color.Red;
tk.Label.ForeColor = Color.White;

sList.AxisFactor.AxisItems[0].ExtraTicks.Add(tk);

sList.SeriesCollection[0].AxisIndex = 1;

this.hHippoChart1.Designer.BackColor = Color.LightBlue;
this.hHippoChart1.Designer.BackLineColor = Color.SkyBlue;

this.hHippoChart1.Titles.Label.Text = "";
this.hHippoChart1.LegendBox.Visible = false;
this.hHippoChart1.SeriesListDictionary.Add(sList);
this.hHippoChart1.DrawChart();


VB
 
Dim en As New. HippoEngine()
en.DataType = DataSourceType.Excel
en.Query = "select * from [Sheet1$]"
en.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`C:\Users\neohippo\Dropbox\Projects\_Hippochart\Hippo 4.1\Hippo Chart 2010 4\HippoChartBeta\WindowsHippoTest\주식차트샘플2.xls`;Extended Properties=`Excel 12.0;HDR=YES`"

Dim sList As SeriesList = en.GetSeriesListOfStock(DataSourceType.Excel, "년/월", "시가", "종가", "저가", "고가")

sList.AxisFactor.AxisItems.Add(New Axis(AxisType.Ytype))
sList.AxisFactor.AxisItems(0).SetAxisStep(10000, 40000, 5000)

sList.AxisFactor.YAxis.Visible = False

sList.ChartType = ChartType.CandleStick
sList.SeriesCollection(0).Name = "주가 "
sList.GraphArea.Grid.Interval = 10
sList.AxisFactor.XAxis.Interval = 15
sList.AxisFactor.YAxis.SetAxisStep(10000, 40000, 5000)

Dim tempMaxHighval As Double = Double.MinValue
Dim tempMaxLowval As Double = Double.MaxValue

Dim Highitem As New. SeriesItem()
Dim Lowitem As New. SeriesItem()

For Each item As SeriesItem In sList.SeriesCollection(0).items
If item.HighValue > tempMaxHighval Then
tempMaxHighval = item.HighValue
Highitem = item
End If

If item.LowValue < tempMaxLowval Then
tempMaxLowval = item.LowValue
Lowitem = item
End If
Next

If Highitem IsNot Nothing Then
Highitem.Balloon = New Balloon()
Highitem.Balloon.BalloonType = BalloonType.Rectangle
Highitem.Balloon.HeightType = HeightType.Bottom
Highitem.Balloon.BackColor = Color.Transparent
Highitem.Balloon.Label.Text = "최고가 : " & Highitem.HighValue.ToString()
Highitem.Balloon.IsShadow = False
Highitem.Balloon.Label.ForeColor = Color.Blue
Highitem.Balloon.Line.LineColor = Color.Transparent
End If

If Lowitem IsNot Nothing Then
Lowitem.Balloon = New Balloon()
Lowitem.Balloon.BalloonType = BalloonType.Rectangle
Lowitem.Balloon.HeightType = HeightType.Bottom
Lowitem.Balloon.BackColor = Color.Transparent
Lowitem.Balloon.Label.Text = "최저가 : " & Highitem.LowValue.ToString()
Lowitem.Balloon.IsShadow = False
Lowitem.Balloon.Label.ForeColor = Color.Red
Lowitem.Balloon.Line.LineColor = Color.Transparent
End If

sList.SeriesCollection(0).items(11).Balloon = New Balloon()
sList.SeriesCollection(0).items(11).Balloon.BalloonType = BalloonType.Rectangle
sList.SeriesCollection(0).items(11).Balloon.BackColor = Color.White
sList.SeriesCollection(0).items(11).Balloon.HeightType = HeightType.Bottom
sList.SeriesCollection(0).items(11).Balloon.Label.Text = "유상증자 ( 0.00% )"

Dim sr2 As New. Series()
sr2.Name = "Trend1"
sr2.ChartType = ChartType.AreaLine
sr2.Points.Width = 0
sr2.Transparency = 99
sr2.Line.LineWidth = 2
sr2.SeriesColor = Color.Yellow

Dim rg As New. Regression()
rg.XYCount = sList.SeriesCollection(0).items.Count
rg.Degree(4)

Dim count As Integer = 0
For Each item As SeriesItem In sList.SeriesCollection(0).items
rg.XYAdd(count, item.YValue)

count += 1
Next

For j As Integer = 0 To 999
rg.RegVal(j)
Next

For i As Integer = 0 To sList.SeriesCollection(0).items.Count - 1
Dim item2 As New. SeriesItem()
item2.Name = sList.SeriesCollection(0).items(i).Name
item2.YValue = rg.Coeff(4) * Math.Pow(i, 4) + rg.Coeff(3) * Math.Pow(i, 3) + rg.Coeff(2) * Math.Pow(i, 2) + rg.Coeff(1) * i + rg.Coeff(0)
item2.YStartValue = item2.YValue - 1500 * (New Random().[Next](6))

sr2.items.Add(item2)
Next

Dim sr3 As New. Series()
sr3.Name = "Trend2"
sr3.ChartType = ChartType.Line
sr3.Line.LineWidth = 2
sr3.Points.Width = 0

rg = New Regression()
rg.XYCount = sList.SeriesCollection(0).items.Count
rg.Degree(1)

count = 0
For Each item As SeriesItem In sList.SeriesCollection(0).items
rg.XYAdd(count, item.HighValue)

count += 1
Next

For j As Integer = 0 To 999
rg.RegVal(j)
Next

For i As Integer = 0 To sList.SeriesCollection(0).items.Count - 1
Dim item2 As New. SeriesItem()

item2.Name = sList.SeriesCollection(0).items(i).Name
item2.YValue = rg.Coeff(1) * i + rg.Coeff(0)

sr3.items.Add(item2)
Next

sList.SeriesCollection.Add(sr2)
sList.SeriesCollection.Add(sr3)

sList.AxisFactor.AxisItems(0).Decimalpoint = 0

Dim tk As New. AxisTick(27670)
tk.Label.Font = New Font("굴림", 9, FontStyle.Regular)
tk.Label.Text = "25,670"
tk.BackColor = Color.Red
tk.Label.ForeColor = Color.White

sList.AxisFactor.AxisItems(0).ExtraTicks.Add(tk)

sList.SeriesCollection(0).AxisIndex = 1

Me.hHippoChart1.Designer.BackColor = Color.LightBlue
Me.hHippoChart1.Designer.BackLineColor = Color.SkyBlue

Me.hHippoChart1.Titles.Label.Text = ""
Me.hHippoChart1.LegendBox.Visible = False
Me.hHippoChart1.SeriesListDictionary.Add(sList)
Me.hHippoChart1.DrawChart()



※ 히포차트 샘플 코드는 버전별로 상이한 결과를 나타낼 수 있습니다.

이 코드 관련 문의 사항은 페이스북 리플을 달아주시거나 아래 이메일로 이 페이지 주소와 함께 문의주세요.

helpdesk@hippochart.com





Copyright © 2009-2016, HippoChart. Inc.  All Rights Reserved.