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 IntelligentControlForsx.Service.AGC; using IntelligentControlForsx.Service.AGC.Domain; using log4net; using WisdomClient.data; namespace IntelligentControlForsx.MyControls.agc { public partial class WindLineChart : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); private string actualDataPoint; public string ActualDataPoint { set { actualDataPoint = value; } get { return actualDataPoint; } } private string setDataPoint; public string SetDataPoint { set { setDataPoint = value; } get { return setDataPoint; } } private string title; public string Title { set { title = value; } get { return title; } } public WindLineChart() { InitializeComponent(); } public void BindPointAndTitle(string actualPoint, string setPoint, string title) { this.actualDataPoint = actualPoint; this.setDataPoint = setPoint; this.title = title; } 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) { this.chartData.Series[0].Points.Clear(); this.chartData.Series[1].Points.Clear(); DateTime now = DateTime.Now; chartData.ChartAreas[0].AxisX.Minimum = now.AddHours(-8).ToOADate(); chartData.ChartAreas[0].AxisX.Maximum = now.ToOADate(); IList actualList = dataActual.Distinct(new DataCompare()).ToList(); IList setList = dataSet.Distinct(new DataCompare()).ToList(); foreach (var td in actualList) { DateTime dt = CommonMethod.ConvertIntDateTime(td.ts); this.chartData.Series[0].Points.AddXY(dt, td.doubleValue.Value); } foreach (var td in setList) { DateTime dt = CommonMethod.ConvertIntDateTime(td.ts); this.chartData.Series[1].Points.AddXY(dt, td.doubleValue.Value); } logger.Info("AGC曲线控件绑定:实发有功数据量=" + dataActual.Count + ",有功设定数据量=" + dataSet.Count); } public void ClearTest() { this.chartData.Series[0].Points.Clear(); this.chartData.Series[1].Points.Clear(); } private void chartData_DoubleClick(object sender, EventArgs e) { LineForm form = new LineForm(actualDataPoint, setDataPoint, title); form.StartPosition = FormStartPosition.CenterParent; form.ShowDialog(); } } }