using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace IntelligentControlForsx.MyControls { public partial class DatePower : UserControl { public DatePower() { InitializeComponent(); } public void DataBind(IList list) { var ds = ConvertListToDataSet1(list); //设置图表X轴对应项 chart2.Series[0].XValueMember = "Station"; //设置图表Y轴对应项 chart2.Series[0].YValueMembers = "Power"; chart2.Series[0]["PointWidth"] = "0.682"; chart2.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Transparent; chart2.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Transparent; chart2.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.FromArgb(74,153,196); chart2.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.FromArgb(74, 153, 196); chart2.ChartAreas[0].BackColor = System.Drawing.Color.Transparent; chart2.ChartAreas[0].AxisX.LabelStyle.Font = new Font("微软雅黑", 11, FontStyle.Regular); chart2.ChartAreas[0].AxisY.LabelStyle.Font = new Font("微软雅黑", 11, FontStyle.Regular); chart2.ChartAreas[0].AxisY.Enabled = AxisEnabled.False; chart2.DataSource = ds; chart2.DataBind(); } private void chart2_Click(object sender, EventArgs e) { } private void Chart1_Load(object sender, EventArgs e) { } private void webfontLable1_Load(object sender, EventArgs e) { } private void chart2_Click_1(object sender, EventArgs e) { } private DataSet ConvertListToDataSet1(IList list) { Type elementType = typeof(Info); var ds = new DataSet(); var t = new DataTable(); ds.Tables.Add(t); elementType.GetProperties().ToList().ForEach(propInfo => t.Columns.Add(propInfo.Name, Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType)); foreach (Info item in list) { var row = t.NewRow(); elementType.GetProperties().ToList().ForEach(propInfo => row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value); t.Rows.Add(row); } return ds; } } }