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; using IntelligentControlForsx.Common; using log4net; using WisdomClient.data; namespace IntelligentControlForsx.MyControls.agc { public partial class SunLineChart : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); public SunLineChart() { InitializeComponent(); } private void LineChart_Load(object sender, EventArgs e) { chartData.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm"; chartData.Series[0].XValueType = ChartValueType.DateTime; } private void chartData_GetToolTipText(object sender, ToolTipEventArgs e) { if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint) { try { int i = e.HitTestResult.PointIndex; //DataPoint dp = e.HitTestResult.Series.Points[i]; DataPoint dp1 = this.chartData.Series[0].Points[i]; DataPoint dp2 = this.chartData.Series[1].Points[i]; //分别显示x轴和y轴的数值,其中{1:F3},表示显示的是float类型,精确到小数点后3位。 e.Text = string.Format("时间:{0};\n风速:{1:F2};\n功率:{2:F2};", dp1.XValue, dp1.YValues[0], dp2.YValues[0]); } catch (Exception ex) { logger.Info(ex.Message); } } } public void DataBind(IList dataActual, IList dataSet) { DateTime now = DateTime.Now; chartData.ChartAreas[0].AxisX.Minimum = now.AddHours(-8).ToOADate(); chartData.ChartAreas[0].AxisX.Maximum = now.ToOADate(); this.chartData.Series[0].Points.Clear(); this.chartData.Series[1].Points.Clear(); foreach (var td in dataActual) { DateTime dt = CommonMethod.ConvertIntDateTime(td.ts); this.chartData.Series[0].Points.AddXY(dt, td.doubleValue.Value); } foreach (var td in dataSet) { DateTime dt = CommonMethod.ConvertIntDateTime(td.ts); this.chartData.Series[1].Points.AddXY(dt, td.doubleValue.Value); } } } }