public AreaSpectrumMonitor( Panel parentControl, Int32 resolution, Double xAxisMax, String title, Color lineColor ) { m_iResolution = resolution; _chart = new LightningChartUltimate(); _chart.ChartName = "Area spectrum chart"; _chart.ViewXY.XAxes = ViewXY.CreateDefaultXAxes(); _chart.ViewXY.YAxes = ViewXY.CreateDefaultYAxes(); _chart.VerticalAlignment = VerticalAlignment.Top; _chart.HorizontalAlignment = HorizontalAlignment.Left; _chart.BeginUpdate(); _chart.Title.Visible = true; _chart.Title.Text = title; _chart.Title.Color = lineColor; _chart.Title.Font = new WpfFont("Segoe UI", 13, true, false); _chart.Title.Offset.SetValues(0, 20); _chart.ChartBackground.Color = ChartTools.CalcGradient(lineColor, Colors.Black, 65); _chart.ChartBackground.GradientDirection = 0; _chart.ChartBackground.GradientFill = GradientFill.Cylindrical; _chart.ViewXY.GraphBackground.GradientDirection = 270; _chart.ViewXY.GraphBackground.GradientFill = GradientFill.Linear; _chart.ViewXY.ZoomPanOptions.ZoomRectLine.Color = Colors.White; _chart.ViewXY.GraphBordersOverSeries = false; _chart.ViewXY.AxisLayout.YAxesLayout = YAxesLayout.Layered; _chart.ViewXY.AxisLayout.AutoAdjustMargins = false; Color color = _chart.ViewXY.GraphBackground.Color; _chart.ViewXY.GraphBackground.Color = Color.FromArgb(150, color.R, color.G, color.B); AxisX axisX = _chart.ViewXY.XAxes[0]; axisX.SetRange(0, xAxisMax); axisX.Title.Font = new WpfFont("Segoe UI", 13, true, false); axisX.Title.Visible = true; axisX.Title.Text = "Frequency (Hz)"; axisX.Units.Visible = false; axisX.ValueType = AxisValueType.Number; axisX.Position = 100; axisX.LabelsPosition = Alignment.Far; axisX.MajorDivTickStyle.Alignment = Alignment.Far; axisX.MinorDivTickStyle.Alignment = Alignment.Far; axisX.MajorDivTickStyle.Color = Colors.Gray; axisX.MinorDivTickStyle.Color = Colors.DimGray; axisX.LabelsColor = Colors.White; axisX.LabelsFont = new WpfFont("Segoe UI", 11, true, false); axisX.ScrollMode = XAxisScrollMode.None; axisX.Title.Visible = false; AxisY axisY = _chart.ViewXY.YAxes[0]; axisY.MajorDivTickStyle.Color = Colors.Gray; axisY.MinorDivTickStyle.Color = Colors.DimGray; axisY.AutoFormatLabels = false; axisY.LabelsNumberFormat = "0"; axisY.SetRange(0, 7000000); axisY.Title.Visible = false; axisY.LabelsColor = Colors.White; axisY.LabelsFont = new WpfFont("Segoe UI", 11, true, false); axisY.Units.Visible = false; axisY.Visible = false; AreaSeries areaSeries = new AreaSeries(_chart.ViewXY, axisX, axisY); areaSeries.Title.Visible = false; areaSeries.LineStyle.Color = lineColor; areaSeries.LineStyle.Width = 1f; areaSeries.Fill.Color = ChartTools.CalcGradient(lineColor, Colors.Black, 50); areaSeries.Fill.GradientFill = GradientFill.Solid; areaSeries.MouseInteraction = false; areaSeries.PointsVisible = false; _chart.ViewXY.AreaSeries.Add(areaSeries); _chart.EndUpdate(); _chart.ViewXY.ZoomPanOptions.MouseWheelZooming = MouseWheelZooming.Off; parentControl.Children.Add(_chart); }
/// <summary> /// 构造函数 /// </summary> /// <param name="parentControl">父容器</param> /// <param name="seriesNames">示波器各序列名</param> /// <param name="sampleFrequency">绘制曲线颜色</param> /// <param name="titleColor">绘制曲线颜色</param> /// <param name="chartManager"> 内置图表的的chartManager(可空)</param> public WaveformMonitor( Panel parentControl, string[] seriesNames, double sampleFrequency, Color titleColor, ChartManager chartManager ) { _samplingFrequency = sampleFrequency; _parentControl = parentControl; _chart = new LightningChartUltimate(); _chart.ChartName = "Waveform chart"; _chart.ViewXY.XAxes = ViewXY.CreateDefaultXAxes(); _chart.ViewXY.YAxes = ViewXY.CreateDefaultYAxes(); _chart.VerticalAlignment = VerticalAlignment.Top; _chart.HorizontalAlignment = HorizontalAlignment.Left; _chart.ViewXY.AxisLayout.YAxesLayout = YAxesLayout.Stacked; _chart.ViewXY.AxisLayout.SegmentsGap = 10; parentControl.Children.Add(_chart); _chart.BeginUpdate(); _chart.ChartManager = chartManager; _chart.ViewXY.AxisLayout.AutoAdjustMargins = false; _chart.ViewXY.DropOldSeriesData = true; _chart.ChartRenderOptions.AntiAliasLevel = 0; // Disable hw anti-aliasing. AxisX axisX = _chart.ViewXY.XAxes[0]; axisX.Maximum = 10; axisX.SweepingGap = 2; axisX.ScrollMode = XAxisScrollMode.Scrolling; axisX.Title.Text = "Range"; axisX.Title.VerticalAlign = XAxisTitleAlignmentVertical.Top; axisX.Title.HorizontalAlign = XAxisTitleAlignmentHorizontal.Right; axisX.LabelsPosition = Alignment.Near; axisX.LabelsFont = new WpfFont("Segoe UI", 11, true, false); axisX.MajorDivTickStyle.Visible = false; axisX.MinorDivTickStyle.Visible = false; axisX.MajorGrid.Visible = false; axisX.MinorGrid.Visible = false; axisX.LabelsVisible = false; axisX.SteppingInterval = 1; axisX.MouseScaling = false; axisX.MouseScrolling = false; axisX.AxisThickness = 1; //AxisY axisY = _chart.ViewXY.YAxes[0]; //axisY.SetRange(-30000, 30000); //axisY.Title.Visible = false; //axisY.LabelsFont = new WpfFont("Segoe UI", 11, true, false); _chart.ViewXY.GraphBackground.GradientDirection = 270; _chart.ViewXY.GraphBackground.GradientFill = GradientFill.Cylindrical; Color color = _chart.ViewXY.GraphBackground.Color; _chart.ViewXY.GraphBackground.Color = Color.FromArgb(150, color.R, color.G, color.B); _chart.Title.Font = new WpfFont("Segoe UI", 14, true, false); _chart.Title.Align = ChartTitleAlignment.TopCenter; _chart.Title.Offset.SetValues(0, 25); _chart.Title.Color = titleColor; _chart.ViewXY.Margins = new Thickness(70, 10, 15, 10); _chart.ViewXY.ZoomPanOptions.ZoomRectLine.Color = Colors.Lime; _chart.ChartBackground.Color = ChartTools.CalcGradient(titleColor, Colors.Black, 65); _chart.ChartBackground.GradientDirection = 0; _chart.ChartBackground.GradientFill = GradientFill.Cylindrical; //清除之前的y轴与数据序列 DisposeAllAndClear(_chart.ViewXY.YAxes); DisposeAllAndClear(_chart.ViewXY.SampleDataSeries); //添加多序列的y轴属性 for (int index = 0; index < seriesNames.Count(); index++) { AxisY axisY = new AxisY(_chart.ViewXY); axisY.SetRange(-30000, 30000); axisY.Title.Font = new WpfFont("Segoe UI", 10, false, false); axisY.Title.Text = string.Format(seriesNames[index]); axisY.Title.Angle = 0; axisY.Units.Visible = false; //axisY.Title.Visible = false; axisY.LabelsFont = new WpfFont("Segoe UI", 11, true, false); _chart.ViewXY.YAxes.Add(axisY); //Add SampleDataSeries SampleDataSeries sds = new SampleDataSeries(_chart.ViewXY, axisX, axisY); _chart.ViewXY.SampleDataSeries.Add(sds); sds.SampleFormat = SampleFormat.DoubleFloat; sds.LineStyle.Color = DefaultColors.SeriesForBlackBackgroundWpf[index % DefaultColors.SeriesForBlackBackgroundWpf.Length]; sds.SamplingFrequency = _samplingFrequency; sds.FirstSampleTimeStamp = 1.0 / _samplingFrequency; sds.LineStyle.Width = 1f; sds.LineStyle.AntiAliasing = LineAntialias.None; sds.ScrollModePointsKeepLevel = 1; sds.ScrollingStabilizing = true; sds.MouseInteraction = false; //Add the line as a zero level ConstantLine cls = new ConstantLine(_chart.ViewXY, axisX, axisY); cls.Title.Text = "Constant line"; cls.Title.Visible = false; cls.LineStyle.Color = Colors.BlueViolet; cls.Behind = true; cls.LineStyle.Width = 2; cls.MouseInteraction = false; cls.Value = 0; _chart.ViewXY.ConstantLines.Add(cls); } //LineSeriesCursor cursor1 = new LineSeriesCursor(_chart.ViewXY, axisX); //cursor1.ValueAtXAxis = 1; //cursor1.LineStyle.Width = 6; //color = Colors.OrangeRed; //cursor1.LineStyle.Color = Color.FromArgb(180, color.R, color.G, color.B); //cursor1.FullHeight = true; //cursor1.SnapToPoints = true; //cursor1.Style = CursorStyle.PointTracking; //cursor1.TrackPoint.Color1 = Colors.Yellow; //cursor1.TrackPoint.Color2 = Colors.Transparent; //cursor1.TrackPoint.Shape = Shape.Circle; //_chart.ViewXY.LineSeriesCursors.Add(cursor1); _chart.EndUpdate(); }
/// <summary> /// 构造 /// </summary> /// <param name="parentControl">父控件</param> /// <param name="verticalScrolling">是否可以垂直滚动</param> /// <param name="resolution">分辨率</param> /// <param name="timeStepMs"></param> /// <param name="timeRangeLengthSec"></param> /// <param name="freqMin">最小频率</param> /// <param name="freqMax">最大频率</param> /// <param name="title">频谱仪标题(未使用)</param> /// <param name="toneColor"></param> public SpectrogramViewXYIntensity(Panel parentControl, bool verticalScrolling, int resolution, double timeStepMs, double timeRangeLengthSec, double freqMin, double freqMax, string title, Color toneColor) { _parentControl = parentControl; double dDefaultYMax = 7000000; double dAxisTimeScaleMin = timeStepMs / 1000.0 - timeRangeLengthSec; double dAxisTimeScaleMax = 0; m_dStepTime = timeStepMs / 1000.0; m_dTimeRangeLengthSec = timeRangeLengthSec; //Create chart LightningChartUltimate chart = new LightningChartUltimate(); _chart = chart; _chart.VerticalAlignment = VerticalAlignment.Top; _chart.HorizontalAlignment = HorizontalAlignment.Left; m_bIsHorizontalScrolling = !verticalScrolling; chart.BeginUpdate(); parentControl.Children.Add(chart); _chart.ChartBackground.Color = ChartTools.CalcGradient(toneColor, Colors.Black, 65); _chart.ChartBackground.GradientDirection = 0; _chart.ChartBackground.GradientFill = GradientFill.Cylindrical; chart.ChartName = "Spectrogram chart"; chart.ViewXY.XAxes = ViewXY.CreateDefaultXAxes(); chart.ViewXY.YAxes = ViewXY.CreateDefaultYAxes(); chart.Title.Visible = false; chart.Title.Font = new WpfFont("Segoe UI", 13, true, false); chart.Title.Offset.SetValues(0, 20); chart.ViewXY.ZoomPanOptions.RightMouseButtonAction = MouseButtonAction.None; chart.ViewXY.ZoomPanOptions.LeftMouseButtonAction = MouseButtonAction.None; chart.ViewXY.ZoomPanOptions.MouseWheelZooming = MouseWheelZooming.Off; //Disable automatic axis layouts chart.ViewXY.AxisLayout.AutoAdjustMargins = false; chart.ViewXY.AxisLayout.XAxisAutoPlacement = XAxisAutoPlacement.Off; chart.ViewXY.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.Off; chart.ViewXY.AxisLayout.XAxisTitleAutoPlacement = false; chart.ViewXY.AxisLayout.YAxisTitleAutoPlacement = false; chart.ViewXY.Margins = new Thickness(60, 10, 15, 50); if (m_bIsHorizontalScrolling) { chart.ViewXY.XAxes[0].ValueType = AxisValueType.Time; chart.ViewXY.XAxes[0].Title.Text = "Time"; chart.ViewXY.XAxes[0].SetRange(dAxisTimeScaleMin, dAxisTimeScaleMax); chart.ViewXY.YAxes[0].ValueType = AxisValueType.Number; chart.ViewXY.YAxes[0].Title.Text = "Frequency(Hz)"; chart.ViewXY.YAxes[0].SetRange(freqMin, freqMax); } else { chart.ViewXY.XAxes[0].ValueType = AxisValueType.Number; chart.ViewXY.XAxes[0].Title.Text = "Frequency(Hz)"; chart.ViewXY.XAxes[0].SetRange(freqMin, freqMax); chart.ViewXY.YAxes[0].ValueType = AxisValueType.Time; chart.ViewXY.YAxes[0].Title.Text = "Time"; chart.ViewXY.YAxes[0].SetRange(dAxisTimeScaleMin, dAxisTimeScaleMax); } m_dCurrentTime = dAxisTimeScaleMax; Color color = Colors.White; chart.ViewXY.XAxes[0].MinorDivTickStyle.Visible = false; chart.ViewXY.XAxes[0].LabelsColor = Color.FromArgb(200, color.R, color.G, color.B); chart.ViewXY.XAxes[0].MajorDivTickStyle.Color = Colors.Orange; chart.ViewXY.XAxes[0].Title.Shadow.Style = TextShadowStyle.Off; chart.ViewXY.XAxes[0].LabelsNumberFormat = "0"; chart.ViewXY.YAxes[0].MinorDivTickStyle.Visible = false; chart.ViewXY.YAxes[0].LabelsColor = Color.FromArgb(200, color.R, color.G, color.B); chart.ViewXY.YAxes[0].MajorDivTickStyle.Color = Colors.Orange; chart.ViewXY.YAxes[0].Title.Shadow.Style = TextShadowStyle.Off; chart.ViewXY.YAxes[0].LabelsNumberFormat = "0"; //Setup legend box chart.ViewXY.LegendBoxes = ViewXY.CreateDefaultLegendBoxes(); chart.ViewXY.LegendBoxes[0].SeriesTitleColor = toneColor; chart.ViewXY.LegendBoxes[0].ValueLabelColor = Colors.White; chart.ViewXY.LegendBoxes[0].IntensityScales.ScaleBorderColor = Colors.White; chart.ViewXY.LegendBoxes[0].Position = LegendBoxPositionXY.RightCenter; chart.ViewXY.LegendBoxes[0].Layout = LegendBoxLayout.Vertical; chart.ViewXY.LegendBoxes[0].Offset.SetValues(-20, 0); chart.ViewXY.LegendBoxes[0].Fill.Style = RectFillStyle.None; chart.ViewXY.LegendBoxes[0].Shadow.Visible = false; chart.ViewXY.LegendBoxes[0].BorderWidth = 0; chart.ViewXY.LegendBoxes[0].IntensityScales.ScaleSizeDim1 = 100; chart.ViewXY.LegendBoxes[0].IntensityScales.ScaleSizeDim2 = 15; chart.ViewXY.LegendBoxes[0].ShowCheckboxes = false; chart.ViewXY.LegendBoxes[0].UnitsColor = Colors.Transparent; chart.Name = "Spectrogram"; //Create grid _grid = new IntensityGridSeries(chart.ViewXY, chart.ViewXY.XAxes[0], chart.ViewXY.YAxes[0]); chart.ViewXY.IntensityGridSeries.Add(_grid); m_iSizeTimeSlots = (int)Math.Round(timeRangeLengthSec / (timeStepMs / 1000.0)); m_iSizeResolution = resolution; m_aFastData = new double[m_iSizeTimeSlots][]; for (int iTimeSlot = 0; iTimeSlot < m_iSizeTimeSlots; iTimeSlot++) { m_aFastData[iTimeSlot] = new double[m_iSizeResolution]; } if (m_bIsHorizontalScrolling) { _grid.SetValuesData(m_aFastData, IntensityGridValuesDataOrder.ColumnsRows); } else { _grid.SetValuesData(m_aFastData, IntensityGridValuesDataOrder.RowsColumns); } _grid.Data = null; _grid.SetRangesXY(chart.ViewXY.XAxes[0].Minimum, chart.ViewXY.XAxes[0].Maximum, chart.ViewXY.YAxes[0].Minimum, chart.ViewXY.YAxes[0].Maximum); _grid.ContourLineType = ContourLineTypeXY.None; _grid.WireframeType = SurfaceWireframeType.None; _grid.PixelRendering = true; _grid.MouseInteraction = false; _grid.ValueRangePalette = CreatePalette(_grid, dDefaultYMax); _grid.Title.Text = "P(f)"; chart.EndUpdate(); }