public MainWindow()
        {
            InitializeComponent();

            // Create chart.
            // This is done using XAML.

            // Disable rendering before updating chart properties to improve performance
            // and to prevent unnecessary chart redrawing while changing multiple properties.
            chart.BeginUpdate();

            // Create variable for view from ViewXY.
            // This is done using XAML.

            // Set title options for X- and Y-axis.
            // This is done using XAML.

            // Set label angle for X-axis.
            // This is done using XAML.

            // Disable autoformating of labels.
            // This is done using XAML.

            // Enable CustomAxisTicks.
            // This is done using XAML.

            // 1. Create a new BarSeries.
            // This is done using XAML.

            // Add styling to created series.
            barSeries1.Fill.Color        = Color.FromRgb(255, 165, 0); // Orange.
            barSeries1.Fill.GradientFill = GradientFill.Solid;
            barSeries1.Title.Text        = "2017";
            barSeries1.BarThickness      = 10;

            // 2. Generate data as BarSeriesValues to represent average monthly temperatures.
            BarSeriesValue[] bars1 = new BarSeriesValue[]
            {
                new BarSeriesValue(0, -5, null),
                new BarSeriesValue(1, -6, null),
                new BarSeriesValue(2, -2, null),
                new BarSeriesValue(3, 4, null),
                new BarSeriesValue(4, 10, null),
                new BarSeriesValue(5, 14, null),
                new BarSeriesValue(6, 17, null),
                new BarSeriesValue(7, 15, null),
                new BarSeriesValue(8, 10, null),
                new BarSeriesValue(9, 6, null),
                new BarSeriesValue(10, -2, null),
                new BarSeriesValue(11, -4, null)
            };

            // Add BarSeriesValues to BarSeries.
            barSeries1.Values = bars1;

            // 3. Add BarSeries to chart.
            // This is done using XAML.

            // 4. Create second BarSeries.
            // This is done using XAML.

            // Add styling to created series.
            barSeries2.Fill.Color        = Color.FromRgb(211, 211, 211); // LightGray.
            barSeries2.Fill.GradientFill = GradientFill.Solid;
            barSeries2.Title.Text        = "2018";
            barSeries2.BarThickness      = 10;

            // 5. Generate an other set of data as BarSeriesValues to represent average monthly temperatures.
            BarSeriesValue[] bars2 = new BarSeriesValue[]
            {
                new BarSeriesValue(0, -1, null),
                new BarSeriesValue(1, -1, null),
                new BarSeriesValue(2, 2, null),
                new BarSeriesValue(3, 8, null),
                new BarSeriesValue(4, 15, null),
                new BarSeriesValue(5, 19, null),
                new BarSeriesValue(6, 21, null),
                new BarSeriesValue(7, 19, null),
                new BarSeriesValue(8, 14, null),
                new BarSeriesValue(9, 8, null),
                new BarSeriesValue(10, 2, null),
                new BarSeriesValue(11, -7, null)
            };

            // Add BarSeriesValues to BarSeries.
            barSeries2.Values = bars2;

            // 6. Add BarSeries to chart.
            // This is done using XAML.

            // 7. Configure bar view layout.
            // This is done using XAML.

            // 8. Create list of months.
            string[] months = new string[]
            {
                "January",
                "February",
                "March",
                "April",
                "May",
                "June",
                "July",
                "August",
                "September",
                "October",
                "November",
                "December"
            };

            // 9. Create CustomAxisTicks to display months as X-axis values.
            for (int i = 0; i < months.Length; i++)
            {
                CustomAxisTick tick = new CustomAxisTick(axisX);
                tick.AxisValue = i;
                tick.LabelText = months[i];
                tick.Color     = Color.FromArgb(35, 255, 255, 255);

                axisX.CustomTicks.Add(tick);
            }

            // Notify chart about set custom axis ticks.
            axisX.InvalidateCustomTicks();

            // Auto-scale X- and Y-axes.
            chart.ViewXY.ZoomToFit();

            #region Hidden polishing
            // Customize chart.
            CustomizeChart(chart);
            #endregion

            // Call EndUpdate to enable rendering again.
            chart.EndUpdate();
        }
        public Form1()
        {
            InitializeComponent();

            // Create chart.
            var chart = new LightningChartUltimate();

            // Disable rendering before updating chart properties to improve performance
            // and to prevent unnecessary chart redrawing while changing multiple properties.
            chart.BeginUpdate();

            // Set chart control into parent container.
            chart.Parent = this;           // Set form as parent.
            chart.Dock   = DockStyle.Fill; // Maximize to parent client area.

            // Define variables for X- and Y-axis.
            var axisX = chart.ViewXY.XAxes[0];
            var axisY = chart.ViewXY.YAxes[0];

            // Set title options for X- and Y-axis.
            axisX.Title.Visible = false;
            axisY.Title.Text    = "Temperature °C";

            // Set label angle for X-axis.
            axisX.LabelsAngle = 90;

            // LegendBox layout.
            chart.ViewXY.LegendBoxes[0].Position = LegendBoxPositionXY.SegmentTopRight;

            // Disable autoformating of labels.
            axisX.AutoFormatLabels = false;

            // Enable CustomAxisTicks.
            axisX.CustomTicksEnabled = true;

            // 1. Create a new BarSeries.
            var barSeries1 = new BarSeries(chart.ViewXY, axisX, axisY);

            // Add styling to created series.
            barSeries1.Fill.Color        = Color.Orange;
            barSeries1.Fill.GradientFill = GradientFill.Solid;
            barSeries1.Title.Text        = "2017";
            barSeries1.BarThickness      = 10;

            // 2. Generate data as BarSeriesValues to represent average monthly temperatures.
            BarSeriesValue[] bars1 = new BarSeriesValue[]
            {
                new BarSeriesValue(0, -5, null),
                new BarSeriesValue(1, -6, null),
                new BarSeriesValue(2, -2, null),
                new BarSeriesValue(3, 4, null),
                new BarSeriesValue(4, 10, null),
                new BarSeriesValue(5, 14, null),
                new BarSeriesValue(6, 17, null),
                new BarSeriesValue(7, 15, null),
                new BarSeriesValue(8, 10, null),
                new BarSeriesValue(9, 6, null),
                new BarSeriesValue(10, -2, null),
                new BarSeriesValue(11, -4, null)
            };

            // Add BarSeriesValues to BarSeries.
            barSeries1.Values = bars1;

            // 3. Add BarSeries to chart.
            chart.ViewXY.BarSeries.Add(barSeries1);

            // 4. Create second BarSeries.
            var barSeries2 = new BarSeries();

            // Add styling to created series.
            barSeries2.Fill.Color        = Color.LightGray;
            barSeries2.Fill.GradientFill = GradientFill.Solid;
            barSeries2.Title.Text        = "2018";
            barSeries2.BarThickness      = 10;

            // 5. Generate an other set of data as BarSeriesValues to represent average monthly temperatures.
            BarSeriesValue[] bars2 = new BarSeriesValue[]
            {
                new BarSeriesValue(0, -1, null),
                new BarSeriesValue(1, -1, null),
                new BarSeriesValue(2, 2, null),
                new BarSeriesValue(3, 8, null),
                new BarSeriesValue(4, 15, null),
                new BarSeriesValue(5, 19, null),
                new BarSeriesValue(6, 21, null),
                new BarSeriesValue(7, 19, null),
                new BarSeriesValue(8, 14, null),
                new BarSeriesValue(9, 8, null),
                new BarSeriesValue(10, 2, null),
                new BarSeriesValue(11, -7, null)
            };

            // Add BarSeriesValues to BarSeries.
            barSeries2.Values = bars2;

            // 6. Add BarSeries to chart.
            chart.ViewXY.BarSeries.Add(barSeries2);

            // 7. Configure bar view layout.
            chart.ViewXY.BarViewOptions.Grouping = BarsGrouping.ByLocation;

            // 8. Create list of months.
            string[] months = new string[]
            {
                "January",
                "February",
                "March",
                "April",
                "May",
                "June",
                "July",
                "August",
                "September",
                "October",
                "November",
                "December"
            };

            // 9. Create CustomAxisTicks to display months as X-axis values.
            for (int i = 0; i < months.Length; i++)
            {
                CustomAxisTick tick = new CustomAxisTick(axisX);
                tick.AxisValue = i;
                tick.LabelText = months[i];
                tick.Color     = Color.FromArgb(35, 255, 255, 255);

                axisX.CustomTicks.Add(tick);
            }

            // Notify chart about set custom axis ticks.
            axisX.InvalidateCustomTicks();

            // Auto-scale X- and Y-axes.
            chart.ViewXY.ZoomToFit();

            #region Hidden polishing
            // Customize chart.
            CustomizeChart(chart);
            #endregion

            // Call EndUpdate to enable rendering again.
            chart.EndUpdate();
        }
        private void UpdateChart(List <BaseAlarmSignal> sglist)
        {
            _chart.BeginUpdate();
            _chart.ViewXY.BarSeries.Clear();
            _chart.ViewXY.XAxes[0].CustomTicks.Clear();

            var devicelist  = sglist.GroupBy(p => p.OrganizationDeviceName).ToList();
            int pointsCount = devicelist.Count;
            var max         = devicelist.Select(p => p.Select(c => c.PreAlarmCount + c.AlarmCount + c.DangerCount).Sum()).Max();// sglist.Max(p => p.AlarmCount + p.PreAlarmCount + p.DangerCount);
            int with        = (int)((_chart.ActualWidth - 100) / (pointsCount + 1) - 20) / 3;

            _chart.ViewXY.YAxes[0].SetRange(0, max);
            _chart.ViewXY.XAxes[0].SetRange(0.0, (double)(pointsCount + 1));
            // Add a bar series for each point, with a different color.
            for (int i = 0; i < 3; i++)
            {
                BarSeriesValue[] data = new BarSeriesValue[pointsCount];
                for (int j = 0; j < pointsCount; j++)
                {
                    if (i == 0)
                    {
                        data[j].Value    = devicelist[j].Select(p => p.PreAlarmCount).Sum();
                        data[j].Location = j + 1;
                        //Set label text

                        data[j].Text = data[j].Value.ToString("0");
                        data[j].Tag  = data[j].Value.ToString("0");
                    }
                    else if (i == 1)
                    {
                        data[j].Value    = devicelist[j].Select(p => p.AlarmCount).Sum();
                        data[j].Location = j + 1;
                        //Set label text
                        data[j].Text = data[j].Value.ToString("0");
                        data[j].Tag  = data[j].Value.ToString("0");
                    }
                    else if (i == 2)
                    {
                        data[j].Value    = devicelist[j].Select(p => p.DangerCount).Sum();
                        data[j].Location = j + 1;
                        //Set label text
                        data[j].Text = data[j].Value.ToString("0");
                        data[j].Tag  = data[j].Value.ToString("0");
                    }

                    if (i == 0)
                    {
                        // Let's use custom axis ticks to display days of the month.
                        CustomAxisTick tick = new CustomAxisTick(_chart.ViewXY.XAxes[0]);
                        tick.AxisValue = (double)(j + 1);
                        tick.LabelText = devicelist[j].Select(p => p.DeviceName).FirstOrDefault();
                        tick.Length    = 0;
                        _chart.ViewXY.XAxes[0].CustomTicks.Add(tick);
                    }
                }
                BarSeries bs = new BarSeries(_chart.ViewXY, _chart.ViewXY.XAxes[0], _chart.ViewXY.YAxes[0]);
                //Set series title
                if (i == 0)
                {
                    bs.Title.Text = "预警";
                }
                else if (i == 1)
                {
                    bs.Title.Text = "警告";
                }
                else if (i == 2)
                {
                    bs.Title.Text = "危险";
                }
                //Set series fill
                //bs.Fill.Color = DefaultColors.SeriesForBlackBackgroundWpf[index];
                //bs.Fill.GradientColor = ChartTools.CalcGradient(DefaultColors.SeriesForBlackBackgroundWpf[index], Colors.Black, 50);
                //bs.BorderColor = ChartTools.CalcGradient(bs.Fill.Color, Colors.Black, 70);

                if (i == 0)
                {
                    bs.Fill.Color = Color.FromArgb(255, 0xff, 0xd4, 0x00);//黄色
                }
                else if (i == 1)
                {
                    bs.Fill.Color = Color.FromArgb(255, 0xf4, 0x79, 0x20);//橙色
                }
                else if (i == 2)
                {
                    bs.Fill.Color = Color.FromArgb(255, 0xd7, 0x13, 0x45);//红色
                }
                bs.Fill.GradientFill = GradientFill.Solid;
                //bs.Fill.GradientColor = ChartTools.CalcGradient(bs.Fill.Color, Colors.Black, 50);
                //bs.Fill.GradientDirection = 0;
                //bs.Fill.Style = RectFillStyle.ColorOnly;
                //bs.BarThickness = 100;
                //bs.Shadow.Visible = true;
                //bs.Shadow.Offset.SetValues(2, 2);
                //bs.BorderColor = ChartTools.CalcGradient(bs.Fill.Color, Colors.Black, 70);
                //bs.LabelStyle.Shadow.Style = TextShadowStyle.DropShadow;

                bs.Shadow.Visible = false;
                //bs.Shadow.Offset.SetValues(2, 2);

                //Set label text style
                bs.LabelStyle.Angle         = 0;
                bs.LabelStyle.VerticalAlign = BarsTitleVerticalAlign.BarCenter;

                //Assign the value
                bs.Values       = data;
                bs.BarThickness = with;

                _chart.ViewXY.BarSeries.Add(bs);
            }
            _chart.EndUpdate();

            gridChart.SizeChanged += gridChart_SizeChanged;
        }