CgImageForm.cs 4.8 KB

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