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

주식차트 마우스무브 이벤트로 십자 라인 그리기







주식차트를 그리실 경우 마우스를 갖다대면 그 포인트에 맞게 십자 라인을 그리고 수치를 표시한다던가 하는 작업이 있을 수 있는데 관련된 이벤트 구현 방법 코드 참고하십시오.




차트 영역 드래그 하기  마우스 Move 이벤트를 통해 수치 표현  박스플롯차트 마우스 이벤트(수치보기)  범례 클릭 마우스 이벤트 주기  주식차트 마우스무브 이벤트로 십자 라인 그리기  라인차트 마우스무브 이벤트 데이터 수치 보이기  히포차트 4.3 - 현재 마우스가 위치한 곳의 YValue 값 알기  


C#
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Hippo;

namespace Candlesample
{
public partial class Form1 : Form
{
SeriesList sList;
SeriesList sList2;

int time = 0;

public Form1()
{
InitializeComponent();
}

///
/// 그리기
///

///
///
private void button1_Click(object sender, EventArgs e)
{
this.hHippoChart1.SeriesListDictionary.Clear();

HippoEngine en = new HippoEngine();
en.DataType = DataSourceType.Excel;
en.Query = "select * from [Sheet1$]";
en.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`"+ System.IO.Directory.GetCurrentDirectory() +"\\주식차트샘플2.xls`;Extended Properties=`Excel 12.0;HDR=YES`";

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

sList.ChartType = ChartType.CandleStick;

sList.SeriesCollection[0].Name = "주가";

sList.AxisFactor.YAxis.SetAxisStep(0, 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 (item.IsDojiType)
{

}
}


this.hHippoChart1.LegendBox.Visible = false;
this.hHippoChart1.SeriesListDictionary.Add(sList);
this.hHippoChart1.DrawChart();





AxisTick tk2 = new AxisTick(new PointF(0, this.hHippoChart1.SeriesListDictionary[0].AxisFactor.Zero.Y));
tk2.IsShowGridLine = true;
tk2.GridLine.LineColor = Color.Blue;
tk2.GridLine.LineWidth = 5;
sList.AxisFactor.XAxis.ExtraTicks.Add(tk2);

AxisTick tk1 = new AxisTick(new PointF(this.hHippoChart1.SeriesListDictionary[0].AxisFactor.Zero.X, 0));
tk1.IsShowGridLine = true;
tk1.GridLine.LineColor = Color.Blue;
tk1.GridLine.LineWidth = 5;
sList.AxisFactor.YAxis.ExtraTicks.Add(tk1);
}

///
/// 차트 크기가 변경될때 발생하는 이벤트
///

///
///
private void hHippoChart1_ChartSizeChanged(object sender, EventArgs e)
{
// 새로고침
this.hHippoChart1.DrawChart();
}

///
/// 실시간 차트형태로 보기 샘플
///

///
///
private void button2_Click(object sender, EventArgs e)
{
this.hHippoChart1.SeriesListDictionary.Clear();
this.timer1.Interval = 1000;

sList2 = new SeriesList();
sList2.ChartType = ChartType.CandleStick;
sList2.SeriesCollection.Add(new Series());
sList2.AxisFactor.XAxis.Interval = 2;

// 실시간 셋 추가
this.hHippoChart1.RealTimeList.Add(new Hippo.WindowsForm4.HippoRealTimeAttribute());

this.hHippoChart1.SeriesListDictionary.Add(sList2);
//this.hHippoChart1.DrawChart();

this.timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
try
{
this.hHippoChart1.DrawRealTimeChart(sList.SeriesCollection[0].items[time], 10);

time++;
}
catch
{
this.timer1.Stop();
}
}

private void Form1_Load(object sender, EventArgs e)
{
this.hHippoChart1.DrawChart();
}

private void hHippoChart1_ChartMouseMove(object sender, MouseEventArgs e)
{
if (this.hHippoChart1.SeriesListDictionary.Count > 0)
{
double zeroX = this.hHippoChart1.SeriesListDictionary[0].AxisFactor.Zero.X;
double zeroY = this.hHippoChart1.SeriesListDictionary[0].AxisFactor.Zero.Y;

double coodiRecHeight = this.hHippoChart1.Size.Height;

float cX = (float)(zeroX + (e.X - this.hHippoChart1.SeriesListDictionary[0].GraphArea.LeftAxisRectangle.Width - 20));
float cY = (float)(zeroY - (coodiRecHeight - e.Y
- this.hHippoChart1.SeriesListDictionary[0].GraphArea.BottomAxisRectangle.Height
- this.hHippoChart1.SeriesListDictionary[0].Margin
- Figures.LogoSpareEmpty - 10
));

this.label2.Text = e.Y.ToString();

sList.AxisFactor.XAxis.ExtraTicks[0].TickPoint = new PointF(cX, this.hHippoChart1.SeriesListDictionary[0].AxisFactor.Zero.Y);
sList.AxisFactor.YAxis.ExtraTicks[0].TickPoint = new PointF(this.hHippoChart1.SeriesListDictionary[0].AxisFactor.Zero.X, cY);

this.hHippoChart1.DrawChart();
}
}
}
}


VB
 
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Hippo

Namespace Candlesample
Public Partial Class Form1
Inherits Form
Private sList As SeriesList
Private sList2 As SeriesList

Private time As Integer = 0

Public Sub New()
InitializeComponent()
End Sub

```
``` 그리기
```

```
```
Private Sub button1_Click(sender As Object, e As EventArgs)
Me.hHippoChart1.SeriesListDictionary.Clear()

Dim en As New. HippoEngine()
en.DataType = DataSourceType.Excel
en.Query = "select * from [Sheet1$]"
en.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`" & System.IO.Directory.GetCurrentDirectory() & "\주식차트샘플2.xls`;Extended Properties=`Excel 12.0;HDR=YES`"

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

sList.ChartType = ChartType.CandleStick

sList.SeriesCollection(0).Name = "주가"

sList.AxisFactor.YAxis.SetAxisStep(0, 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


If item.IsDojiType Then
End If
Next


Me.hHippoChart1.LegendBox.Visible = False
Me.hHippoChart1.SeriesListDictionary.Add(sList)
Me.hHippoChart1.DrawChart()





Dim tk2 As New. AxisTick(New PointF(0, Me.hHippoChart1.SeriesListDictionary(0).AxisFactor.Zero.Y))
tk2.IsShowGridLine = True
tk2.GridLine.LineColor = Color.Blue
tk2.GridLine.LineWidth = 5
sList.AxisFactor.XAxis.ExtraTicks.Add(tk2)

Dim tk1 As New. AxisTick(New PointF(Me.hHippoChart1.SeriesListDictionary(0).AxisFactor.Zero.X, 0))
tk1.IsShowGridLine = True
tk1.GridLine.LineColor = Color.Blue
tk1.GridLine.LineWidth = 5
sList.AxisFactor.YAxis.ExtraTicks.Add(tk1)
End Sub

```
``` 차트 크기가 변경될때 발생하는 이벤트
```

```
```
Private Sub hHippoChart1_ChartSizeChanged(sender As Object, e As EventArgs)
` 새로고침
Me.hHippoChart1.DrawChart()
End Sub

```
``` 실시간 차트형태로 보기 샘플
```

```
```
Private Sub button2_Click(sender As Object, e As EventArgs)
Me.hHippoChart1.SeriesListDictionary.Clear()
Me.timer1.Interval = 1000

sList2 = New SeriesList()
sList2.ChartType = ChartType.CandleStick
sList2.SeriesCollection.Add(New Series())
sList2.AxisFactor.XAxis.Interval = 2

` 실시간 셋 추가
Me.hHippoChart1.RealTimeList.Add(New Hippo.WindowsForm4.HippoRealTimeAttribute())

Me.hHippoChart1.SeriesListDictionary.Add(sList2)
`this.hHippoChart1.DrawChart();

Me.timer1.Start()
End Sub

Private Sub timer1_Tick(sender As Object, e As EventArgs)
Try
Me.hHippoChart1.DrawRealTimeChart(sList.SeriesCollection(0).items(time), 10)

time += 1
Catch
Me.timer1.[Stop]()
End Try
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs)
Me.hHippoChart1.DrawChart()
End Sub

Private Sub hHippoChart1_ChartMouseMove(sender As Object, e As MouseEventArgs)
If Me.hHippoChart1.SeriesListDictionary.Count > 0 Then
Dim zeroX As Double = Me.hHippoChart1.SeriesListDictionary(0).AxisFactor.Zero.X
Dim zeroY As Double = Me.hHippoChart1.SeriesListDictionary(0).AxisFactor.Zero.Y

Dim coodiRecHeight As Double = Me.hHippoChart1.Size.Height

Dim cX As Single = CSng(zeroX + (e.X - Me.hHippoChart1.SeriesListDictionary(0).GraphArea.LeftAxisRectangle.Width - 20))
Dim cY As Single = CSng(zeroY - (coodiRecHeight - e.Y - Me.hHippoChart1.SeriesListDictionary(0).GraphArea.BottomAxisRectangle.Height - Me.hHippoChart1.SeriesListDictionary(0).Margin - Figures.LogoSpareEmpty - 10))

Me.label2.Text = e.Y.ToString()

sList.AxisFactor.XAxis.ExtraTicks(0).TickPoint = New PointF(cX, Me.hHippoChart1.SeriesListDictionary(0).AxisFactor.Zero.Y)
sList.AxisFactor.YAxis.ExtraTicks(0).TickPoint = New PointF(Me.hHippoChart1.SeriesListDictionary(0).AxisFactor.Zero.X, cY)

Me.hHippoChart1.DrawChart()
End If
End Sub
End Class
End Namespace


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

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

helpdesk@hippochart.com





Copyright © 2009-2018 HippoChart. Inc.  All Rights Reserved.