SunLineChart.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 log4net;
  13. using WisdomClient.data;
  14. namespace IntelligentControlForsx.MyControls.agc
  15. {
  16. public partial class SunLineChart : UserControl
  17. {
  18. private ILog logger = LogManager.GetLogger("AppInfoLog");
  19. public SunLineChart()
  20. {
  21. InitializeComponent();
  22. }
  23. private void LineChart_Load(object sender, EventArgs e)
  24. {
  25. chartData.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm";
  26. chartData.Series[0].XValueType = ChartValueType.DateTime;
  27. }
  28. private void chartData_GetToolTipText(object sender, ToolTipEventArgs e)
  29. {
  30. if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint)
  31. {
  32. try
  33. {
  34. int i = e.HitTestResult.PointIndex;
  35. //DataPoint dp = e.HitTestResult.Series.Points[i];
  36. DataPoint dp1 = this.chartData.Series[0].Points[i];
  37. DataPoint dp2 = this.chartData.Series[1].Points[i];
  38. //分别显示x轴和y轴的数值,其中{1:F3},表示显示的是float类型,精确到小数点后3位。
  39. e.Text = string.Format("时间:{0};\n风速:{1:F2};\n功率:{2:F2};", dp1.XValue, dp1.YValues[0], dp2.YValues[0]);
  40. }
  41. catch (Exception ex)
  42. {
  43. logger.Info(ex.Message);
  44. }
  45. }
  46. }
  47. public void DataBind(IList<TsData> dataActual, IList<TsData> dataSet)
  48. {
  49. DateTime now = DateTime.Now;
  50. chartData.ChartAreas[0].AxisX.Minimum = now.AddHours(-8).ToOADate();
  51. chartData.ChartAreas[0].AxisX.Maximum = now.ToOADate();
  52. this.chartData.Series[0].Points.Clear();
  53. this.chartData.Series[1].Points.Clear();
  54. foreach (var td in dataActual)
  55. {
  56. DateTime dt = CommonMethod.ConvertIntDateTime(td.ts);
  57. this.chartData.Series[0].Points.AddXY(dt, td.doubleValue.Value);
  58. }
  59. foreach (var td in dataSet)
  60. {
  61. DateTime dt = CommonMethod.ConvertIntDateTime(td.ts);
  62. this.chartData.Series[1].Points.AddXY(dt, td.doubleValue.Value);
  63. }
  64. }
  65. }
  66. }