using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Editors;
using Steema.TeeChart.Styles;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 에디터
/// </summary>
private Editor editor;
/// <summary>
/// 시리즈 그룹 1
/// </summary>
private SeriesGroup seriesGroup1;
/// <summary>
/// 시리즈 그룹 2
/// </summary>
private SeriesGroup seriesGroup2;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.seriesGroupComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
this.seriesGroupComboBox.DisplayMember = "Name";
this.showGroupsAsEditorCheckBox.Checked = true;
this.showAllGroupsAtEditorCheckBox.Checked = true;
Text = "SeriesGroup 클래스 : 시리즈 그룹 사용하기";
this.tChart.Panel.Pen = new ChartPen(Color.Black);
for(int i = 0; i < 10; i++)
{
Line line = new Line(this.tChart.Chart);
line.Title = $"line{i}";
line.FillSampleValues();
}
this.seriesGroup1 = tChart.Series.AddGroup("그룹 1");
this.seriesGroup1.Series.Add(tChart.Series[0]);
this.seriesGroup1.Series.Add(tChart.Series[2]);
this.seriesGroup1.Series.Add(tChart.Series[4]);
this.seriesGroup1.Series.Add(tChart.Series[6]);
this.seriesGroup1.Series.Add(tChart.Series[8]);
this.seriesGroup1.Show();
this.seriesGroup2 = this.tChart.Series.AddGroup("그룹 2");
this.seriesGroup2.Series.Add(tChart.Series[1]);
this.seriesGroup2.Series.Add(tChart.Series[3]);
this.seriesGroup2.Series.Add(tChart.Series[5]);
this.seriesGroup2.Series.Add(tChart.Series[7]);
this.seriesGroup2.Series.Add(tChart.Series[9]);
this.seriesGroup2.Hide();
this.chartListBox.Chart = this.tChart;
this.chartListBox.SeriesGroup = this.seriesGroup1;
for(int i = 0; i < tChart.Series.Groups.Count; i++)
{
this.seriesGroupComboBox.Items.Add(this.tChart.Series.Groups[i]);
}
this.seriesGroupComboBox.SelectedIndex = 0;
ChartEditorOptions[] optionsArray = new ChartEditorOptions[8];
optionsArray[0] = ChartEditorOptions.Help;
optionsArray[1] = ChartEditorOptions.Add;
optionsArray[2] = ChartEditorOptions.Delete;
optionsArray[3] = ChartEditorOptions.Change;
optionsArray[4] = ChartEditorOptions.Clone;
optionsArray[5] = ChartEditorOptions.Groups;
optionsArray[6] = ChartEditorOptions.GroupAll;
optionsArray[7] = ChartEditorOptions.Title;
this.editor = new Editor(this.tChart);
this.editor.AlwaysShowFuncSrc = false;
this.editor.HighLightTabs = false;
this.editor.Options = optionsArray;
this.seriesGroupComboBox.SelectedIndexChanged += seriesGroupComboBox_SelectedIndexChanged;
this.editButton.Click += editButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 시리즈 콤보 박스 선택 인덱스 변경시 처리하기 - seriesGroupComboBox_SelectedIndexChanged(sender, e)
/// <summary>
/// 시리즈 콤보 박스 선택 인덱스 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void seriesGroupComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
this.chartListBox.SeriesGroup.Hide();
this.chartListBox.SeriesGroup = this.seriesGroupComboBox.SelectedItem as SeriesGroup;
this.chartListBox.SeriesGroup.Show();
}
#endregion
#region 편집 버튼 클릭시 처리하기 - editButton_Click(sender, e)
/// <summary>
/// 편집 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void editButton_Click(object sender, EventArgs e)
{
List<ChartEditorOptions> list = new List<ChartEditorOptions>();
list.AddRange(this.editor.Options);
if(this.showGroupsAsEditorCheckBox.Checked && list.IndexOf(ChartEditorOptions.Groups) < 0)
{
list.Add(ChartEditorOptions.Groups);
}
if(!this.showGroupsAsEditorCheckBox.Checked)
{
list.Remove(ChartEditorOptions.Groups);
}
if(this.showAllGroupsAtEditorCheckBox.Checked && list.IndexOf(ChartEditorOptions.GroupAll) < 0)
{
list.Add(ChartEditorOptions.GroupAll);
}
if(!this.showAllGroupsAtEditorCheckBox.Checked)
{
list.Remove(ChartEditorOptions.GroupAll);
}
this.editor.Options = (ChartEditorOptions[])list.ToArray();
this.editor.ShowModal(this);
}
#endregion
}
}