본문 바로가기
C#/DevExpress

[C# DevExpress] ChartControl - BubbleChart

by 샤나엘 2018. 4. 9.
반응형


C# Bubble Chart에 대한 사용예제입니다.

 

아래와 같은 Chart형태가 BubbleChart입니다.

 

 

Series의 ViewType을 Bubble로 설정합니다.

 

다른 차트와 다르게 Series의 값에 Bubble크기를 설정하는 Argument를 하나 더 추가해서 설정해야합니다.

 

SeriesPoint point = new SeriesPoint(x축 값, y축 값, bubble 크기값);

 

 

[사용코드]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
private void SetBubbleChartData(ChartControl chart, DataTable dt)
        {
            ViewType viewType = ViewType.Bubble;
 
            Dictionary<string, Series> seriesInfo = new Dictionary<string, Series>();
 
            Random rand = new Random();
            foreach (DataRow row in dt.Rows)
            {
                string product = row["PRODUCT"].ToString();
                string year = row["YEAR"].ToString();
                int qty = (int)row["QTY"];
 
                Series series;
                if (seriesInfo.TryGetValue(product, out series) == false)
                {
                    series = new Series(product, viewType);
                    seriesInfo.Add(product, series);
                    series.ArgumentScaleType = ScaleType.Qualitative;
                    chart.Series.Add(series);
                }
 
                SeriesPoint point = new SeriesPoint(year, qty, qty);
                series.Points.Add(point);
            }
 
            //ChartTitle 생성
            ChartTitle title = new ChartTitle();
            title.Text = viewType.ToString();
            chart.Titles.Add(title);
        }

 


===================================================================

 

[Y축 최대, 최소값 변경 방법]

위 차트 그림에서 상단부분이 잘려서 표시가 되는 것을 확인하실 수 있습니다.

해당 부분이 거슬려서 Y축 값을 변경해서 원이 잘리지 않게 표시되도록 해보았습니다.

 

 

 

XYDiagram의 AxisY.WholeRange의 MaxValue, MinValue 값을 설정해주면 됩니다.

아래 소스에서 빨간색으로 표시한 부분을 참고하시면 됩니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
private void SetBubbleChartData(ChartControl chart, DataTable dt)
        {
            ViewType viewType = ViewType.Bubble;
 
            Dictionary<string, Series> seriesInfo = new Dictionary<string, Series>();
 
            Random rand = new Random();
            foreach (DataRow row in dt.Rows)
            {
                string product = row["PRODUCT"].ToString();
                string year = row["YEAR"].ToString();
                int qty = (int)row["QTY"];
 
                Series series;
                if (seriesInfo.TryGetValue(product, out series) == false)
                {
                    series = new Series(product, viewType);
                    seriesInfo.Add(product, series);
                    series.ArgumentScaleType = ScaleType.Qualitative;
                    chart.Series.Add(series);
                }
 
                SeriesPoint point = new SeriesPoint(year, qty, qty);
                series.Points.Add(point);
            }
 
            (chart.Diagram as XYDiagram).AxisY.WholeRange.MaxValue = 140; // y축 최대값
            (chart.Diagram as XYDiagram).AxisY.WholeRange.MinValue = -10; // y축 최소값
            (chart.Diagram as XYDiagram).AxisY.WholeRange.Auto = false// y축 범위 자동변경 설정
 
            //ChartTitle 생성
            ChartTitle title = new ChartTitle();
            title.Text = viewType.ToString();
            chart.Titles.Add(title);
        }


반응형

댓글