728x90
728x170

차트의 Legend 의 Series Click 시 선택 Series 를 강조할 때 사용하는 코드

using Steema.TeeChart.Styles;

namespace Win.TeeChartLegendClickTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            // Set SampleData
            for (int i = 0; i < 10; i++)
            {
                Points points = new Points(this.tChart1.Chart);

                points.FillSampleValues(20);
            }

            this.tChart1.ClickLegend += TChart1_ClickLegend;
            this.tChart1.MouseClick += TChart1_MouseClick;
        }

        private void TChart1_ClickLegend(object? sender, MouseEventArgs e)
        {
            int index = this.tChart1.Legend.Clicked(e.X, e.Y);

            if (index > -1)
            {
                for (int i = 0; i < this.tChart1.Series.Count; i++)
                {
                    // 선택된 Legend 강조
                    this.tChart1[i].Transparency = 0;

                    if (i != index)
                    {
                        // 선택되지 않은 항목 반?투명하게 처리
                        this.tChart1[i].Transparency = 70;
                    }
                }
            }
        }

        private void TChart1_MouseClick(object? sender, MouseEventArgs e)
        {
            // Legend 영역이 아닌 경우 모두 원상태로 돌리기
            int index = this.tChart1.Legend.Clicked(e.X, e.Y);

            if (index > -1)
            {
                return;
            }
            else
            {
                for (int i = 0; i < this.tChart1.Series.Count; i++)
                {
                    this.tChart1[i].Transparency = 0;
                }
            }
        }
    }
}

위 코드 내용은 ClickLegend 에서 이벤트를 받아 Chart.Legend.Clicked(e.X, e.Y) 을 이용해
클릭한 좌표에 있는 Series 의 Index 를 반환하고
Index 에 해당하는 Series 를 제외한 나머지 Series 를 불투명 하게 만든다.

그런데 .NET6  에서는 버그가 있다 .Net Framework 는 아주 잘동작한다.
하지만 .NET6 는 뒤쪽에 있는 Series 를 클릭할 때 자기것이 아닌 위쪽 Series 를 강조하게되는 버그가 있다.
아래 gif 이미지를 보면 처음엔 잘 강조하다가 뒤로 가면 갈수록 엉뚱한걸 강조한다;;


[Source]
https://github.com/kei-soft/Win.TeeChartTest

728x90
그리드형
Posted by kjun
,