CgImageForm.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using DevExpress.Charts.Native;
  2. using DevExpress.Map.Dashboard;
  3. using DevExpress.Map.Native;
  4. using DevExpress.XtraBars;
  5. using DevExpress.XtraCharts;
  6. using DevExpress.XtraEditors.Repository;
  7. using ExtensionsDev;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Forms;
  18. using System.Windows.Media.Imaging;
  19. using XdCxRhDW.Api;
  20. namespace XdCxRhDW.App.CorTools
  21. {
  22. public partial class CgImageForm : DevExpress.XtraEditors.XtraForm
  23. {
  24. List<ImageResult> list;
  25. public CgImageForm()
  26. {
  27. InitializeComponent();
  28. int w = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Width;
  29. int h = (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Height;
  30. Bitmap bmp = new Bitmap(w, h);
  31. for (int x = 0; x < w; x++)
  32. {
  33. for (int y = 0; y < h; y++)
  34. {
  35. var rgbb = ColorRGB.GetSpecColor(x / 1d / w);
  36. int r = rgbb.R;
  37. int g = rgbb.G;
  38. int b = rgbb.B;
  39. Color c = Color.FromArgb(r, g, b);
  40. bmp.SetPixel(x, y, c);
  41. }
  42. }
  43. var bgColor = ColorRGB.GetSpecColor(0);
  44. chartControl1.BackColor = bgColor;
  45. (this.chartControl1.Diagram as XYDiagram).DefaultPane.BackColor = bgColor;
  46. (this.chartControl1.AnnotationRepository[0] as ImageAnnotation).Image.DXImage = bmp;
  47. (this.chartControl1.AnnotationRepository[1] as TextAnnotation).BackColor = bgColor;
  48. (this.chartControl1.AnnotationRepository[1] as TextAnnotation).TextColor = Color.White;
  49. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).BackColor = bgColor;
  50. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).TextColor = Color.White;
  51. (this.chartControl1.Diagram as XYDiagram).AxisX.Color = Color.White;
  52. (this.chartControl1.Diagram as XYDiagram).AxisX.Label.TextColor = Color.White;
  53. (this.chartControl1.Diagram as XYDiagram).AxisY.Color = Color.White;
  54. (this.chartControl1.Diagram as XYDiagram).AxisY.Label.TextColor = Color.White;
  55. this.chartControl1.Series[0].ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;
  56. (this.chartControl1.Series[0].View as PointSeriesView).PointMarkerOptions.Size = 12;//点的大小
  57. //ToolTipPointPattern可以参考以下网站说明
  58. //https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.ToolTipPointPattern?utm_source=visualstudio&utm_medium=DXHelpAssistant&utm_campaign=onlinehelp
  59. this.chartControl1.Series[0].ToolTipPointPattern = "{A:f3}us\r\n{V:f3}Hz\r\n{}dB";
  60. }
  61. public CgImageForm(List<ImageResult> list)
  62. : this()
  63. {
  64. this.list = list;
  65. var maxX = (list[0].XMax - 1 + list[0].XFlag) * 1e6 / list[0].FsHz;
  66. var minX = (list[0].XFlag) * 1e6 / list[0].FsHz;
  67. var maxY = list.Max(p => p.YValue) + 100;
  68. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).Text = $"共{list.Count}个点";
  69. (this.chartControl1.Diagram as XYDiagram).AxisX.WholeRange.SetMinMaxValues(minX, maxX);
  70. (this.chartControl1.Diagram as XYDiagram).AxisX.VisualRange.SetMinMaxValues(minX, maxX);
  71. (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY);
  72. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY);
  73. }
  74. private void Test_Load(object sender, EventArgs e)
  75. {
  76. chartControl1.QueryCursor += ChartControl1_QueryCursor;
  77. foreach (var item in list)
  78. {
  79. double xValue = (item.XValue + item.XFlag) * 1e6 / item.FsHz;//us
  80. this.chartControl1.Series[0].Points.Add(new SeriesPoint()
  81. {
  82. Argument = xValue.ToString(),
  83. Values = new double[1] { item.YValue },
  84. Color = item.GetColor(),
  85. Tag = item.Snr.ToString("f1"),
  86. });
  87. }
  88. }
  89. private void ChartControl1_QueryCursor(object sender, QueryCursorEventArgs e)
  90. {
  91. e.Cursor = Cursors.Default;
  92. }
  93. }
  94. }