using System;
using System.Drawing;
using System.Windows.Forms;
using Arction.WinForms.Charting;
using Arction.WinForms.Charting.Axes;
using Arction.WinForms.Charting.SeriesXY;
using Arction.WinForms.Charting.Views.ViewXY;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 차트
/// </summary>
private LightningChartUltimate chart = null;
/// <summary>
/// 현재 X 범위
/// </summary>
private double currentXRange = 1000.0;
/// <summary>
/// 현재 Y 범위
/// </summary>
private double currentYRange = 1000.0;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
InitializeChart();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region X축 범위 변경시 처리하기 - axisX_RangeChanged(sender, e)
/// <summary>
/// X축 범위 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void axisX_RangeChanged(object sender, RangeChangedEventArgs e)
{
if(e.NewMin < 0.0)
{
double newRange = e.NewMax - e.NewMin;
if(newRange <= 1000.0)
{
this.chart.ViewXY.XAxes[0].SetRange(0.0, newRange);
}
else
{
this.chart.ViewXY.XAxes[0].SetRange(0.0, 1000.0);
}
}
else if(e.NewMax > 1000.0)
{
double newRange = e.NewMax - e.NewMin;
if(newRange <= 1000.0)
{
this.chart.ViewXY.XAxes[0].SetRange(1000.0 - newRange, 1000.0);
}
else
{
this.chart.ViewXY.XAxes[0].SetRange(0, 1000.0);
}
}
else
{
double newRange = e.NewMax - e.NewMin;
this.chart.BeginUpdate();
this.chart.HorizontalScrollBars[0].LargeChange = (ulong)(newRange + 0.5);
this.chart.HorizontalScrollBars[0].Value = (ulong)(e.NewMin + 0.5);
this.chart.EndUpdate();
this.currentXRange = newRange;
}
}
#endregion
#region Y축 범위 변경시 처리하기 - axisY_RangeChanged(sender, e)
/// <summary>
/// Y축 범위 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void axisY_RangeChanged(object sender, RangeChangedEventArgs e)
{
if(e.NewMin < 0.0)
{
double newRange = e.NewMax - e.NewMin;
if(newRange <= 1000.0)
{
this.chart.ViewXY.YAxes[0].SetRange(0.0, newRange);
}
else
{
this.chart.ViewXY.YAxes[0].SetRange(0.0, 1000.0);
}
}
else if(e.NewMax > 1000.0)
{
double newRange = e.NewMax - e.NewMin;
if(newRange <= 1000.0)
{
this.chart.ViewXY.YAxes[0].SetRange(1000.0 - newRange, 1000.0);
}
else
{
this.chart.ViewXY.YAxes[0].SetRange(0, 1000.0);
}
}
else
{
double newRange = e.NewMax - e.NewMin;
this.chart.BeginUpdate();
this.chart.VerticalScrollBars[0].LargeChange = (ulong)(newRange + 0.5);
this.chart.VerticalScrollBars[0].Value = (ulong)(1000.0 - e.NewMax);
this.chart.EndUpdate();
this.currentYRange = newRange;
}
}
#endregion
#region 수평 스크롤바 스크롤시 처리하기 - horizontalScrollBar_Scroll(sender, e)
/// <summary>
/// 수평 스크롤바 스크롤시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void horizontalScrollBar_Scroll(object sender, Arction.WinForms.Charting.ScrollEventArgs e)
{
double newMin = e.NewValue;
if(newMin < 0.0)
{
newMin = 0.0;
}
double newMax = newMin + this.currentXRange;
if(newMax > 1000.0)
{
newMax = 1000.0;
newMin = newMax - this.currentXRange;
}
this.chart.ViewXY.XAxes[0].SetRange(newMin, newMax);
}
#endregion
#region 수직 스크롤바 스크롤시 처리하기 - verticalScrollBar_Scroll(sender, e)
/// <summary>
/// 수직 스크롤바 스크롤시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void verticalScrollBar_Scroll(object sender, Arction.WinForms.Charting.ScrollEventArgs e)
{
double newMin = 1000.0 - (double)e.NewValue - this.currentYRange;
if(newMin < 0.0)
{
newMin = 0.0;
}
double newMax = newMin + this.currentYRange;
if(newMax > 1000.0)
{
newMax = 1000.0;
newMin = newMax - this.currentYRange;
}
this.chart.ViewXY.YAxes[0].SetRange(newMin, newMax);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 차트 초기화하기 - InitializeChart()
/// <summary>
/// 차트 초기화하기
/// </summary>
private void InitializeChart()
{
this.chart = new LightningChartUltimate();
this.chart.BeginUpdate();
this.chart.Name = "chart";
this.chart.Parent = this;
this.chart.Dock = DockStyle.Fill;
this.chart.Title.Font = Font;
this.chart.Title.Text = "Scatter 차트";
ViewXY viewXY = this.chart.ViewXY;
viewXY.AxisLayout.AutoAdjustMargins = false;
viewXY.AxisLayout.XAxisAutoPlacement = XAxisAutoPlacement.AllTop;
viewXY.Margins = new Padding(80, 80, 30, 30);
AxisX axisX = viewXY.XAxes[0];
axisX.Title.Font = Font;
axisX.Title.Text = "X축";
axisX.ValueType = AxisValueType.Number;
axisX.ScrollMode = XAxisScrollMode.None;
axisX.Minimum = 0.0;
axisX.Maximum = this.currentXRange;
AxisY axisY = viewXY.YAxes[0];
axisY.Title.Font = Font;
axisY.Title.Text = "Y축";
axisY.ValueType = AxisValueType.Number;
axisY.Minimum = 0.0;
axisY.Maximum = this.currentYRange;
ChartHelper.SetDarkFlatStyle(this.chart);
FreeformPointLineSeries series = new FreeformPointLineSeries(viewXY, axisX, axisY);
series.Title.Visible = false;
series.Title.Color = series.LineStyle.Color;
series.LineVisible = false;
series.PointsVisible = true;
series.PointStyle.Shape = Shape.Rectangle;
series.PointStyle.Color1 = Color.Yellow;
series.PointStyle.Color2 = Color.Orange;
series.PointStyle.Angle = 45;
series.MouseInteraction = false;
viewXY.FreeformPointLineSeries.Add(series);
HorizontalScrollBar horizontalScrollBar = new HorizontalScrollBar(this.chart);
horizontalScrollBar.Border.Style = BorderType.None;
horizontalScrollBar.Maximum = (ulong)axisX.Maximum;
horizontalScrollBar.Minimum = (ulong)axisX.Minimum;
horizontalScrollBar.LargeChange = (ulong)axisX.Maximum;
horizontalScrollBar.SmallChange = 1;
this.chart.HorizontalScrollBars.Add(horizontalScrollBar);
VerticalScrollBar verticalScrollBar = new VerticalScrollBar(this.chart);
verticalScrollBar.Border.Style = BorderType.None;
verticalScrollBar.Maximum = (ulong)axisY.Maximum;
verticalScrollBar.Minimum = (ulong)axisY.Minimum;
verticalScrollBar.LargeChange = (ulong)axisY.Maximum;
verticalScrollBar.SmallChange = 1;
this.chart.VerticalScrollBars.Add(verticalScrollBar);
int pointCount = 10000;
Random random = new Random();
SeriesPoint[] pointArray = new SeriesPoint[pointCount];
for(int i = 0; i < pointCount; i++)
{
pointArray[i].X = random.NextDouble() * 1000.0;
pointArray[i].Y = random.NextDouble() * 1000.0;
}
this.chart.ViewXY.FreeformPointLineSeries[0].Points = pointArray;
LegendBoxXY legendBoxXY = viewXY.LegendBoxes[0];
legendBoxXY.Visible = false;
axisX.RangeChanged += axisX_RangeChanged;
axisY.RangeChanged += axisY_RangeChanged;
horizontalScrollBar.Scroll += horizontalScrollBar_Scroll;
verticalScrollBar.Scroll += verticalScrollBar_Scroll;
axisX.SetRange(300, 500);
axisY.SetRange(300, 500);
this.chart.EndUpdate();
}
#endregion
}
}