첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainForm.cs

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 테마 디렉토리 경로
        /// </summary>
        private string themeDirectoryPath;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            Text = "TChart 클래스 : Import/Export 속성을 사용해 차트간 커스텀 팔레트 적용하기";

            this.saveWithTemplateCheckBox.Checked = true;

            this.tChart1.Panel.Pen = new ChartPen(Color.Black);

            SetChartStyle(this.tChart1);

            Points points = new Points(this.tChart1.Chart);

            points.FillSampleValues();

            this.tChart2.Panel.Pen = new ChartPen(Color.Black);

            this.applyThemeButton.Click += applyThemeButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 테마 적용 버튼 클릭시 처리하기 - applyThemeButton_Click(sender, e)

        /// <summary>
        /// 테마 적용 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void applyThemeButton_Click(object sender, EventArgs e)
        {
            SaveCustomTheme();

            this.tChart2.Clear();

            this.tChart2.Import.Theme.Load(Path.Combine(this.themeDirectoryPath, "CustomTheme.xml"));
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 차트 스타일 설정하기 - SetChartStyle(tChart)

        /// <summary>
        /// 차트 스타일 설정하기
        /// </summary>
        /// <param name="tChart">TChart</param>
        private void SetChartStyle(TChart tChart)
        {
            tChart.Aspect.View3D = false;

            tChart.Panel.Gradient.StartColor  = Color.AliceBlue;
            tChart.Panel.Gradient.MiddleColor = Color.SeaShell;
            tChart.Panel.Gradient.EndColor    = Color.Khaki;
            tChart.Panel.Gradient.Visible     = true;
            tChart.Panel.Bevel.Inner          = BevelStyles.Raised;
            tChart.Panel.Bevel.Outer          = BevelStyles.None;

            tChart.Header.Font.Name = "Verdana";
            tChart.Header.Font.Size = 9;

            tChart.Legend.Font.Name = "Verdana";
            tChart.Legend.Font.Size = 7;

            for(int i = 0; i < tChart.Axes.Count; ++i) 
            {
                Axis axis = tChart.Axes[i];

                axis.Labels.Font.Name = "Verdana";
                axis.Labels.Font.Size = 7;
            }
        }

        #endregion
        #region 커스텀 테마 저장하기 - SaveCustomTheme()

        /// <summary>
        /// 커스텀 테마 저장하기
        /// </summary>
        private void SaveCustomTheme()
        {
            this.themeDirectoryPath = Utils.ThemeFolder();

            if(!Directory.Exists(this.themeDirectoryPath))
            {
                this.themeDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            }

            this.tChart1.Export.Theme.SaveWithBase64 = this.saveWithTemplateCheckBox.Checked;

            if(!Directory.Exists(this.themeDirectoryPath))
            {
                Directory.CreateDirectory(this.themeDirectoryPath);
            }

            this.tChart1.Export.Theme.Save(Path.Combine(this.themeDirectoryPath, "CustomTheme.xml"));
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요