using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Media = System.Windows.Media;
using MediaImaging = System.Windows.Media.Imaging;
using System.Windows.Forms;
using Hippo;
using Hippo.ChartControl;
namespace WpfApplication2
{
/// <summary>
/// Window1.xaml에 대한 상호 작용 논리
/// </summary>
public partial class Window1 : Window
{
Timer timer1;
hHippoChart hippo;
/// <summary>
/// 생성자
/// </summary>
public Window1()
{
InitializeComponent();
timer1 = new Timer();
hippo = new hHippoChart();
}
/// <summary>
/// 창 로드 이벤트
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// 히포차트 객체를 windowsFormsHost 의 Child속성에 넣는다.
// 이 코드는 Tick 이벤트에 삽입되면 안됩니다.
this.windowsFormsHost1.Child = hippo;
// 타이머 설정
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
// 차트 크기 설정
hippo.Width2 = (float)this.windowsFormsHost1.Width;
hippo.Height2 = (float)this.windowsFormsHost1.Height;
// 최초 빈 차트를 보여준다.
hippo.DrawChart();
// 시리즈리스트와 시리즈를 각각 한개씩 추가해놓는다.
SeriesList sList = new SeriesList();
sList.SeriesCollection.Add(new Series());
hippo.SeriesListDictionary.Add(sList);
}
/// <summary>
/// 타이머 틱 이벤트
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void timer1_Tick(object sender, EventArgs e)
{
this.txtSecend.Text = DateTime.Now.Second.ToString();
Random rr1 = new Random();
// 그릴 한 개의 데이터를 시리즈아이템으로 생성해서 DrawRealTimeChart에 넘겨준다.
// (여기서는 편의상 랜덤으로 생성했습니다.)
SeriesItem item = new SeriesItem(rr1.Next(999));
item.Points = new Points();
item.Points.Width = 6;
item.Name = DateTime.Now.ToString("mm:ss");
hippo.DrawRealTimeChart(item, 20);
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
this.timer1.Start();
}
private void btnEnd_Click(object sender, RoutedEventArgs e)
{
this.timer1.Stop();
}
}
}
|