using DevExpress.Charts.Native; using DevExpress.Map.Dashboard; using DevExpress.Map.Native; using DevExpress.XtraBars; using DevExpress.XtraCharts; using DevExpress.XtraEditors.Repository; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; using System.Windows.Media.Imaging; using XdCxRhDW.Api; using XdCxRhDW.Dto; namespace XdCxRhDW.App.CorTools { public partial class CgImageForm : DevExpress.XtraEditors.XtraForm { List list; public CgImageForm() { InitializeComponent(); int w = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Width; int h = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Height; Bitmap bmp = new Bitmap(w, h); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { var rgbb = ColorRGB.GetSpecColor(x / 1d / w); int r = rgbb.R; int g = rgbb.G; int b = rgbb.B; Color c = Color.FromArgb(r, g, b); bmp.SetPixel(x, y, c); } } var bgColor = ColorRGB.GetSpecColor(0); chartControl1.BackColor = bgColor; (this.chartControl1.Diagram as XYDiagram).DefaultPane.BackColor = bgColor; (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Image.DXImage = bmp; (this.chartControl1.AnnotationRepository[1] as TextAnnotation).BackColor = bgColor; (this.chartControl1.AnnotationRepository[1] as TextAnnotation).TextColor = Color.White; (this.chartControl1.AnnotationRepository[2] as TextAnnotation).BackColor = bgColor; (this.chartControl1.AnnotationRepository[2] as TextAnnotation).TextColor = Color.White; (this.chartControl1.Diagram as XYDiagram).EnableAxisXZooming = true; (this.chartControl1.Diagram as XYDiagram).EnableAxisYZooming = true; (this.chartControl1.Diagram as XYDiagram).AxisX.Color = Color.White; (this.chartControl1.Diagram as XYDiagram).AxisX.Label.TextColor = Color.White; (this.chartControl1.Diagram as XYDiagram).AxisY.Color = Color.White; (this.chartControl1.Diagram as XYDiagram).AxisY.Label.TextColor = Color.White; this.chartControl1.Series[0].ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True; (this.chartControl1.Series[0].View as PointSeriesView).PointMarkerOptions.Size = 12;//点的大小 //ToolTipPointPattern可以参考以下网站说明 //https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.ToolTipPointPattern?utm_source=visualstudio&utm_medium=DXHelpAssistant&utm_campaign=onlinehelp this.chartControl1.Series[0].ToolTipPointPattern = "{A:f3}us\r\n{V:f3}Hz\r\n{}dB"; } public CgImageForm(List list) : this() { this.list = list; var maxX = (list[0].XMax - 1 + list[0].XFlag) * 1e6 / list[0].FsHz; var minX = (list[0].XFlag) * 1e6 / list[0].FsHz; var maxY = list.Max(p => p.YValue) + 100; if (maxY < 0) maxY = -maxY; (this.chartControl1.AnnotationRepository[2] as TextAnnotation).Text = $"共{list.Count}个点"; (this.chartControl1.Diagram as XYDiagram).AxisX.WholeRange.SetMinMaxValues(minX, maxX); (this.chartControl1.Diagram as XYDiagram).AxisX.VisualRange.SetMinMaxValues(minX, maxX); (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY); (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY); } private void Test_Load(object sender, EventArgs e) { chartControl1.QueryCursor += ChartControl1_QueryCursor; List listPoints = new List(); foreach (var item in list) { double xValue = (item.XValue + item.XFlag) * 1e6 / item.FsHz;//us var point = new SeriesPoint() { Argument = xValue.ToString(), Values = new double[1] { item.YValue }, Color = item.GetColor(), Tag = item.Snr.ToString("f1"), }; listPoints.Add(point); } this.chartControl1.Series[0].Points.AddRange(listPoints.ToArray()); } private void ChartControl1_QueryCursor(object sender, QueryCursorEventArgs e) { e.Cursor = Cursors.Default; } } }