DatePower.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. namespace IntelligentControlForsx.MyControls
  12. {
  13. public partial class DatePower : UserControl
  14. {
  15. public DatePower()
  16. {
  17. InitializeComponent();
  18. }
  19. public void DataBind(IList<Info> list)
  20. {
  21. var ds = ConvertListToDataSet1(list);
  22. //设置图表X轴对应项
  23. chart2.Series[0].XValueMember = "Station";
  24. //设置图表Y轴对应项
  25. chart2.Series[0].YValueMembers = "Power";
  26. chart2.Series[0]["PointWidth"] = "0.682";
  27. chart2.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Transparent;
  28. chart2.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Transparent;
  29. chart2.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.FromArgb(74,153,196);
  30. chart2.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.FromArgb(74, 153, 196);
  31. chart2.ChartAreas[0].BackColor = System.Drawing.Color.Transparent;
  32. chart2.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 11, FontStyle.Regular);
  33. chart2.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 11, FontStyle.Regular);
  34. chart2.ChartAreas[0].AxisY.Enabled = AxisEnabled.False;
  35. chart2.DataSource = ds;
  36. chart2.DataBind();
  37. }
  38. private void chart2_Click(object sender, EventArgs e)
  39. {
  40. }
  41. private void Chart1_Load(object sender, EventArgs e)
  42. {
  43. }
  44. private void webfontLable1_Load(object sender, EventArgs e)
  45. {
  46. }
  47. private void chart2_Click_1(object sender, EventArgs e)
  48. {
  49. }
  50. private DataSet ConvertListToDataSet1(IList<Info> list)
  51. {
  52. Type elementType = typeof(Info);
  53. var ds = new DataSet();
  54. var t = new DataTable();
  55. ds.Tables.Add(t);
  56. elementType.GetProperties().ToList().ForEach(propInfo => t.Columns.Add(propInfo.Name, Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType));
  57. foreach (Info item in list)
  58. {
  59. var row = t.NewRow();
  60. elementType.GetProperties().ToList().ForEach(propInfo => row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value);
  61. t.Rows.Add(row);
  62. }
  63. return ds;
  64. }
  65. }
  66. }