CgImageForm.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. using XdCxRhDW.Dto;
  21. namespace XdCxRhDW.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).AxisX.Color = Color.White;
  53. (this.chartControl1.Diagram as XYDiagram).AxisX.Label.TextColor = Color.White;
  54. (this.chartControl1.Diagram as XYDiagram).AxisY.Color = Color.White;
  55. (this.chartControl1.Diagram as XYDiagram).AxisY.Label.TextColor = Color.White;
  56. this.chartControl1.Series[0].ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;
  57. (this.chartControl1.Series[0].View as PointSeriesView).PointMarkerOptions.Size = 12;//点的大小
  58. //ToolTipPointPattern可以参考以下网站说明
  59. //https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.ToolTipPointPattern?utm_source=visualstudio&utm_medium=DXHelpAssistant&utm_campaign=onlinehelp
  60. this.chartControl1.Series[0].ToolTipPointPattern = "{A:f3}us\r\n{V:f3}Hz\r\n{}dB";
  61. }
  62. public CgImageForm(List<ImageResultDto> list)
  63. : this()
  64. {
  65. this.list = list;
  66. var maxX = (list[0].XMax - 1 + list[0].XFlag) * 1e6 / list[0].FsHz;
  67. var minX = (list[0].XFlag) * 1e6 / list[0].FsHz;
  68. var maxY = list.Max(p => p.YValue) + 100;
  69. if (maxY < 0) maxY = -maxY;
  70. (this.chartControl1.AnnotationRepository[2] as TextAnnotation).Text = $"共{list.Count}个点";
  71. (this.chartControl1.Diagram as XYDiagram).AxisX.WholeRange.SetMinMaxValues(minX, maxX);
  72. (this.chartControl1.Diagram as XYDiagram).AxisX.VisualRange.SetMinMaxValues(minX, maxX);
  73. (this.chartControl1.Diagram as XYDiagram).AxisY.WholeRange.SetMinMaxValues(-maxY, maxY);
  74. (this.chartControl1.Diagram as XYDiagram).AxisY.VisualRange.SetMinMaxValues(-maxY, maxY);
  75. }
  76. private void Test_Load(object sender, EventArgs e)
  77. {
  78. chartControl1.QueryCursor += ChartControl1_QueryCursor;
  79. foreach (var item in list)
  80. {
  81. double xValue = (item.XValue + item.XFlag) * 1e6 / item.FsHz;//us
  82. this.chartControl1.Series[0].Points.Add(new SeriesPoint()
  83. {
  84. Argument = xValue.ToString(),
  85. Values = new double[1] { item.YValue },
  86. Color = item.GetColor(),
  87. Tag = item.Snr.ToString("f1"),
  88. });
  89. }
  90. }
  91. private void ChartControl1_QueryCursor(object sender, QueryCursorEventArgs e)
  92. {
  93. e.Cursor = Cursors.Default;
  94. }
  95. }
  96. }