using DevExpress.Charts.Native; using DevExpress.ClipboardSource.SpreadsheetML; using DevExpress.Utils; using DevExpress.XtraCharts; using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace IStation.WinFrmUI.Monitor { public partial class TimeValueEasyChartView : DevExpress.XtraEditors.XtraUserControl { public TimeValueEasyChartView() { InitializeComponent(); _boxSelHelper = new ChartBoxSelHelper(this.chartControl1); _boxSelHelper.BoxSelCompletedEvent += _boxSelHelper_BoxSelCompletedEvent; _diagram = this.chartControl1.Diagram as SwiftPlotDiagram; _defaultSeries = this.chartControl1.Series[0]; } #region BoxSelHelper private string _boxSelTag;//框选标签 //开始框选 public void StartBoxSel(string tag) { _boxSelTag = tag; _diagram.EnableAxisXScrolling = false; _diagram.EnableAxisXZooming = false; _boxSelHelper.StartBoxSel(); } //结束框选 public void CloseBoxSel() { _boxSelHelper.CloseBoxSel(); } private List _boxSelSeriesPointList = null;//框选点 //框选辅助类 private void _boxSelHelper_BoxSelCompletedEvent(MouseEventArgs obj) { _diagram.EnableAxisXScrolling = true; _diagram.EnableAxisXZooming = true; if (_boxSelHelper == null) return; _boxSelSeriesPointList = _boxSelHelper.CalcuDataTimeSelSeriesPoints(new List() { _defaultSeries }); if (_boxSelSeriesPointList == null || _boxSelSeriesPointList.Count < 1) { _boxSelHelper.CloseBoxSel(); return; } this.popMenu.ShowPopup(MousePosition); } //确认 private void barBtnOk_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.BoxSelCompleteEvent != null) { var list = _boxSelSeriesPointList.Select(x => x.Tag as TimeValue).ToList(); this.BoxSelCompleteEvent.Invoke(_boxSelTag, list); } _boxSelSeriesPointList = null; _boxSelHelper.CloseBoxSel(); } #endregion private SwiftPlotDiagram _diagram;//图表 private Series _defaultSeries; private ChartBoxSelHelper _boxSelHelper = null;//框选辅助类 public event Action> BoxSelCompleteEvent = null;//框选完成事件 /// /// 初始化默认系列 /// /// 数据源 public void InitialDefaultSeries(IEnumerable timeValues) { var lays = this.chartControl1.ShowOverlay(); if (timeValues == null || timeValues.Count() < 1) { _defaultSeries.BindToData(timeValues, null); } else { _defaultSeries.BindToData(timeValues, "Time", "Value"); } GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(2, GCCollectionMode.Forced); GC.WaitForFullGCComplete(); lays.Close(); } public void SetAxisXTitle(string title) { _diagram.AxisX.Title.Text = title; } public void SetAxisYTitle(string title) { _diagram.AxisY.Title.Text = title; } } }