차트의 Bar의 색상을 변경합니다.

 

using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

using DevExpress.XtraCharts;

namespace Dev_Sample
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            Load += mainForm_Load;
        }

        /// <summary>
        /// 메인폼 로드시 동작합니다.
        /// </summary>
        /// <param name="sender">이벤트 발생자 입니다.</param>
        /// <param name="e">이벤트 인자 입니다.</param>
        private void mainForm_Load(object sender, EventArgs e)
        {
            ChartControl chart = new ChartControl();

            chart.DataSource = CreateChartData();

            chart.SeriesDataMember = "Month";
            chart.SeriesTemplate.ArgumentDataMember = "Section";
            chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value" });

            chart.SeriesTemplate.View = new SideBySideBarSeriesView();

            chart.SeriesNameTemplate.BeginText = "Month : ";

            chart.SeriesNameTemplate.BeginText = "Month : ";

            chart.BoundDataChanged += chart_BoundDataChanged;

            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);
        }

        private void chart_BoundDataChanged(object sender, EventArgs e)
        {
            ChartControl chart = (ChartControl)sender;

            for (int i = 0; i < chart.Series.Count; i++)
            {
                BarSeriesView view = (BarSeriesView)chart.Series[i].View;
                view.Color = Color.Blue;
                view.FillStyle.FillMode = FillMode.Gradient;
                ((GradientFillOptionsBase)view.FillStyle.Options).Color2 = Color.Beige;
            }
        }

        private DataTable CreateChartData()
        { 
            DataTable table = new DataTable("Table");

            table.Columns.Add("Month", typeof(string));
            table.Columns.Add("Section", typeof(string));
            table.Columns.Add("Value", typeof(Int32));

            table.Rows.Add(new object[] { "Jan"  , "Section1", 10 });
            table.Rows.Add(new object[] { "Jan"  , "Section2", 20 });
            table.Rows.Add(new object[] { "Jan"  , "Section3", 40 });
            table.Rows.Add(new object[] { "Feb"  , "Section1", 20 });
            table.Rows.Add(new object[] { "Feb"  , "Section2", 30 });
            table.Rows.Add(new object[] { "Feb"  , "Section3", 80 });
            table.Rows.Add(new object[] { "March", "Section1", 30 });
            table.Rows.Add(new object[] { "March", "Section2", 40 });
            table.Rows.Add(new object[] { "March", "Section3", 100 });

            return table;
        }
    }
}

 

차트에 spline, line, bar를 출력합니다.

using System;
using System.Data;
using System.Windows.Forms;

using DevExpress.XtraCharts;

namespace Dev_Sample
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            Load += mainForm_Load;
        }

        /// <summary>
        /// 메인폼 로드시 동작합니다.
        /// </summary>
        /// <param name="sender">이벤트 발생자 입니다.</param>
        /// <param name="e">이벤트 인자 입니다.</param>
        private void mainForm_Load(object sender, EventArgs e)
        {
            ChartControl chart = new ChartControl();

            chart.DataSource = CreateChartData();

            chart.SeriesDataMember = "Month";
            chart.SeriesTemplate.ArgumentDataMember = "Section";
            chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value" });

            chart.SeriesTemplate.View = new SideBySideBarSeriesView();

            chart.SeriesNameTemplate.BeginText = "Month : ";

            chart.SeriesNameTemplate.BeginText = "Month : ";

            chart.BoundDataChanged += chart_BoundDataChanged;

            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);
        }

        private void chart_BoundDataChanged(object sender, EventArgs e)
        {
            ChartControl chart = (ChartControl)sender;

            Series series = chart.GetSeriesByName("Month : Feb");

            if(series != null)
                series.ChangeView(ViewType.Line);

            Series march = chart.GetSeriesByName("Month : March");

            if(march != null)
                march.ChangeView(ViewType.Spline);
        }

        private DataTable CreateChartData()
        { 
            DataTable table = new DataTable("Table");

            table.Columns.Add("Month", typeof(string));
            table.Columns.Add("Section", typeof(string));
            table.Columns.Add("Value", typeof(Int32));

            table.Rows.Add(new object[] { "Jan"  , "Section1", 10 });
            table.Rows.Add(new object[] { "Jan"  , "Section2", 20 });
            table.Rows.Add(new object[] { "Jan"  , "Section3", 40 });
            table.Rows.Add(new object[] { "Feb"  , "Section1", 20 });
            table.Rows.Add(new object[] { "Feb"  , "Section2", 30 });
            table.Rows.Add(new object[] { "Feb"  , "Section3", 80 });
            table.Rows.Add(new object[] { "March", "Section1", 30 });
            table.Rows.Add(new object[] { "March", "Section2", 40 });
            table.Rows.Add(new object[] { "March", "Section3", 100 });

            return table;
        }
    }
}

 

Bar 차트를 생성합니다

 

using System;
using System.Data;
using System.Windows.Forms;

using DevExpress.XtraCharts;

namespace Dev_Sample
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            Load += mainForm_Load;
        }

        /// <summary>
        /// 메인폼 로드시 동작합니다.
        /// </summary>
        /// <param name="sender">이벤트 발생자 입니다.</param>
        /// <param name="e">이벤트 인자 입니다.</param>
        private void mainForm_Load(object sender, EventArgs e)
        {
            ChartControl chart = new ChartControl();

            chart.DataSource = CreateChartData();

            chart.SeriesDataMember = "Month";
            chart.SeriesTemplate.ArgumentDataMember = "Section";
            chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value" });

            chart.SeriesTemplate.View = new StackedBarSeriesView();

            chart.SeriesNameTemplate.BeginText = "Month : ";

            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);
        }

        private DataTable CreateChartData()
        { 
            DataTable table = new DataTable("Table");

            table.Columns.Add("Month", typeof(string));
            table.Columns.Add("Section", typeof(string));
            table.Columns.Add("Value", typeof(Int32));

            table.Rows.Add(new object[] { "Jan", "Section1", 10 });
            table.Rows.Add(new object[] { "Jan", "Section2", 20 });
            table.Rows.Add(new object[] { "Jan", "Section1", 20 });
            table.Rows.Add(new object[] { "Jan", "Section2", 30 });
            table.Rows.Add(new object[] { "Jan", "Section1", 15 });
            table.Rows.Add(new object[] { "Jan", "Section2", 25 });

            return table;
        }
    }
}

개별 차트 시리즈를 데이터에 바인딩하는 예제 입니다.

 

using System;
using System.Data;
using System.Windows.Forms;

using DevExpress.XtraCharts;

namespace Dev_Sample
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();

            Load += mainForm_Load;
        }

        /// <summary>
        /// 메인폼 로드시 동작합니다.
        /// </summary>
        /// <param name="sender">이벤트 발생자 입니다.</param>
        /// <param name="e">이벤트 인자 입니다.</param>
        private void mainForm_Load(object sender, EventArgs e)
        {
            ChartControl chart = new ChartControl();

            Series series = new Series("Series1", ViewType.Bar);
            chart.Series.Add(series);

            series.DataSource = CreateChartData(50);

            series.ArgumentScaleType = ScaleType.Numerical;
            series.ArgumentDataMember = "Argument";
            series.ValueScaleType = ScaleType.Numerical;
            series.ValueDataMembers.AddRange(new string[] { "Value" });

            ((SideBySideBarSeriesView)series.View).ColorEach = true;
            ((XYDiagram)chart.Diagram).AxisX.Visibility = DevExpress.Utils.DefaultBoolean.False;
            chart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;

            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);
        }

        private DataTable CreateChartData(int rowCount)
        { 
            DataTable table = new DataTable("Table");

            table.Columns.Add("Argument", typeof(Int32));
            table.Columns.Add("Value", typeof(Int32));

            Random random = new Random();
            DataRow row = null;

            for (int i = 0; i < rowCount; i++)
            {
                row = table.NewRow();
                row["Argument"] = i;
                row["Value"] = random.Next(100);
                table.Rows.Add(row);
            }

            return table;
        }
    }
}

 

Unbound Column 생성하기 입니다.

GridColumn unboundColumn = this.gridView.Columns.AddField("Test");
unboundColumn.VisibleIndex = this.gridView.Columns.Count;
unboundColumn.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
unboundColumn.OptionsColumn.AllowEdit = false;

위의 코드를 작성하여 Test라는 이름을 가진 언 바운드 컬럼을 생성합니다.

 

private void gridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
	GridView view = sender as GridView;

	if(e.Column.FieldName == "Test" && e.IsGetData)
	{ 
		e.Value = "Test Data";
	}
}

위의 코드를 작성하여 해당 컬럼에 값을 넣어줍니다.

특정 행의 색을 변경합니다.

 

private void gridView_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
	var row = this.gridView.GetRowCellDisplayText(e.RowHandle, "ID");

	if(row.Equals("aaa"))
	{ 
		e.Appearance.BackColor = Color.DarkOrange;
	}
}

GetRowCellDisplayText 메서드에서 두번째 인자는 컬럼 이름을 작성하면 됩니다.

TextEdit에서 천 단위로 끊어서 표기하기(ex: 2,300) 입니다.

 

 this.textEdit.Properties.Mask.EditMask = "n0";
 this.textEdit.Properties.Mask.UseMaskAsDisplayFormat = true;
 this.textEdit.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;

위의 코드를 생성자 안에 작성하면 됩니다.

두 개 이상의 테이블을 결합하여 여러 행을 검색하는 것입니다.

 

SELECT * FROM weather JOIN cities ON (weather.city = cities.name);

실행 결과

 

JOIN TYPE

 

 

SELECT * FROM weather LEFT OUTER JOIN cities ON (weather.city = cities.name);

LEFT JOIN 실행 결과

SELECT CURRENT_USER, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP;

실행 결과

 

이번달의 첫번째 날과 마지막 날 구하기 입니다.

 

SELECT cast(date_trunc('month',current_date) as date) as firstday, (date_trunc('MONTH', current_date) + INTERVAL '1 MONTH - 1 day')::date lastday;

실행 결과

 

+ Recent posts