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 System.Xml.Linq; using XdCxRhDW.Core; using XdCxRhDW.Core.Api; using static DevExpress.XtraEditors.Mask.Design.MaskSettingsForm.DesignInfo.MaskManagerInfo; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; namespace XdCxRhDW.App.CorTools { public partial class CgImageForm : DevExpress.XtraEditors.XtraForm { List list; float maxY; 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).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; maxY = list.Max(p => p.YValue) + 200; (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; chartControl1.Zoom += ChartControl1_Zoom; foreach (var item in list) { double xValue = (item.XValue + item.XFlag) * 1e6 / item.FsHz;//us this.chartControl1.Series[0].Points.Add(new SeriesPoint() { Argument = xValue.ToString(), Values = new double[1] { item.YValue }, Color = item.GetColor(), Tag = item.Snr.ToString("f1"), }); } } private void ChartControl1_QueryCursor(object sender, QueryCursorEventArgs e) { e.Cursor = Cursors.Default; } private void ChartControl1_Zoom(object sender, ChartZoomEventArgs e) { if ((double)e.NewYRange.MinValue < -maxY || (double)e.NewYRange.Max > maxY) { (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY); (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY); } else { if (e.Type == ChartZoomEventType.ZoomOut) { (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues((double)e.NewYRange.MinValue - 10, (double)e.NewYRange.MaxValue + 10); (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues((double)e.NewYRange.MinValue - 10, (double)e.NewYRange.MaxValue + 10); } else { if ((double)e.NewYRange.MaxValue - (double)e.NewYRange.MinValue < 40) { //(this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(e.NewYRange.MinValue, e.NewYRange.MaxValue); (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(e.NewYRange.MinValue, e.NewYRange.MaxValue); } } } } } }