WindLineChart.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Windows.Forms.DataVisualization.Charting;
  11. using IntelligentControlForsx.Common;
  12. using IntelligentControlForsx.Service.AGC;
  13. using IntelligentControlForsx.Service.AGC.Domain;
  14. using log4net;
  15. using WisdomClient.data;
  16. namespace IntelligentControlForsx.MyControls.agc
  17. {
  18. public partial class WindLineChart : UserControl
  19. {
  20. private ILog logger = LogManager.GetLogger("AppInfoLog");
  21. private string actualDataPoint;
  22. public string ActualDataPoint
  23. {
  24. set { actualDataPoint = value; }
  25. get { return actualDataPoint; }
  26. }
  27. private string setDataPoint;
  28. public string SetDataPoint
  29. {
  30. set { setDataPoint = value; }
  31. get { return setDataPoint; }
  32. }
  33. private string title;
  34. public string Title
  35. {
  36. set { title = value; }
  37. get { return title; }
  38. }
  39. public WindLineChart()
  40. {
  41. InitializeComponent();
  42. }
  43. public void BindPointAndTitle(string actualPoint, string setPoint, string title)
  44. {
  45. this.actualDataPoint = actualPoint;
  46. this.setDataPoint = setPoint;
  47. this.title = title;
  48. }
  49. private void LineChart_Load(object sender, EventArgs e)
  50. {
  51. chartData.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";
  52. chartData.Series[0].XValueType = ChartValueType.DateTime;
  53. }
  54. private void chartData_GetToolTipText(object sender, ToolTipEventArgs e)
  55. {
  56. if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint)
  57. {
  58. try
  59. {
  60. int i = e.HitTestResult.PointIndex;
  61. //DataPoint dp = e.HitTestResult.Series.Points[i];
  62. DataPoint dp1 = this.chartData.Series[0].Points[i];
  63. DataPoint dp2 = this.chartData.Series[1].Points[i];
  64. //分别显示x轴和y轴的数值,其中{1:F3},表示显示的是float类型,精确到小数点后3位。
  65. // e.Text = string.Format("时间:{0};\n风速:{1:F2};\n功率:{2:F2};", dp1.XValue, dp1.YValues[0], dp2.YValues[0]);
  66. }
  67. catch (Exception ex)
  68. {
  69. logger.Info(ex.Message);
  70. }
  71. }
  72. }
  73. public void DataBind(IList<TsData> dataActual, IList<TsData> dataSet)
  74. {
  75. this.chartData.Series[0].Points.Clear();
  76. this.chartData.Series[1].Points.Clear();
  77. DateTime now = DateTime.Now;
  78. chartData.ChartAreas[0].AxisX.Minimum = now.AddHours(-8).ToOADate();
  79. chartData.ChartAreas[0].AxisX.Maximum = now.ToOADate();
  80. IList<TsData> actualList = dataActual.Distinct(new DataCompare()).ToList();
  81. IList<TsData> setList = dataSet.Distinct(new DataCompare()).ToList();
  82. foreach (var td in actualList)
  83. {
  84. DateTime dt = CommonMethod.ConvertIntDateTime(td.ts);
  85. this.chartData.Series[0].Points.AddXY(dt, td.doubleValue.Value);
  86. }
  87. foreach (var td in setList)
  88. {
  89. DateTime dt = CommonMethod.ConvertIntDateTime(td.ts);
  90. this.chartData.Series[1].Points.AddXY(dt, td.doubleValue.Value);
  91. }
  92. logger.Info("AGC曲线控件绑定:实发有功数据量=" + dataActual.Count + ",有功设定数据量=" + dataSet.Count);
  93. }
  94. public void ClearTest()
  95. {
  96. this.chartData.Series[0].Points.Clear();
  97. this.chartData.Series[1].Points.Clear();
  98. }
  99. private void chartData_DoubleClick(object sender, EventArgs e)
  100. {
  101. LineForm form = new LineForm(actualDataPoint, setDataPoint, title);
  102. form.StartPosition = FormStartPosition.CenterParent;
  103. form.ShowDialog();
  104. }
  105. }
  106. }