| | |
| | | private XYDiagram _diagram; |
| | | private XYDiagramDefaultPane _default_pane; |
| | | private AxisX _axis_x; |
| | | private AxisY _axis_y; |
| | | private AxisY _axis_y; |
| | | |
| | | private List<Yw.Geometry.Point2d> _point_pt_list; |
| | | private List<Yw.Geometry.Point2d> _line_pt_list; |
| | | |
| | | private Series _series_pt; |
| | | |
| | | private UniversalCoordinate _coordinate; |
| | | private bool _initial_data = false; |
| | |
| | | |
| | | _diagram = (XYDiagram)chartControl1.Diagram; |
| | | _default_pane=_diagram.DefaultPane; |
| | | _axis_x = _diagram.AxisX; |
| | | //_axis_x.SetAxisXQDisplay(); |
| | | _axis_x = _diagram.AxisX; |
| | | _axis_y = _diagram.AxisY; |
| | | //_axis_y.SetAxisYQLDisplay(); |
| | | |
| | | |
| | | |
| | | |
| | | _axis_x.Visibility = DefaultBoolean.False; |
| | | _axis_x.GridLines.Visible = false; |
| | | _axis_y.Visibility = DefaultBoolean.False; |
| | | _axis_y.GridLines.Visible = false; |
| | | |
| | | |
| | | |
| | | this.chartControl1.SetChartMonoColorDisplay(); |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | public void Clear() |
| | | { |
| | | _initial_data = false; |
| | | _point_pt_list = null; |
| | | _line_pt_list = null; |
| | | _coordinate = null; |
| | | _series_pt = null; |
| | | |
| | | this.chartControl1.BeginInit(); |
| | | this.chartControl1.Series.Clear(); |
| | | this.chartControl1.AnnotationRepository.Clear(); |
| | | this.chartControl1.Legend.CustomItems.Clear(); |
| | | this.chartControl1.EndInit(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | | /// </summary> |
| | | public void SetBindingData(List<Yw.Geometry.Point2d> point_pt_list, List<Yw.Geometry.Point2d> line_pt_list, string coordinate = null, Color? color = null) |
| | | { |
| | | _initial_data = false; |
| | | _point_pt_list = point_pt_list; |
| | | _line_pt_list = line_pt_list; |
| | | _coordinate = UniversalCoordinate.ToModel(coordinate); |
| | | _series_pt = null; |
| | | |
| | | this.chartControl1.BeginInit(); |
| | | this.chartControl1.Series.Clear(); |
| | |
| | | this.chartControl1.EndInit(); |
| | | return; |
| | | } |
| | | |
| | | AddPointSeries(color.Value, _axis_x, _axis_y, _default_pane, _point_pt_list); |
| | | AddLineSeries(color.Value, _axis_x, _axis_y, _default_pane, _line_pt_list); |
| | | |
| | | _series_pt = AddPointSeries(color.Value, _axis_x, _axis_y, _default_pane, _point_pt_list); |
| | | AddLineSeries(color.Value, _axis_x, _axis_y, _default_pane, _line_pt_list); |
| | | if (_coordinate == null) |
| | | SetCoordinate(); |
| | | |
| | | SetChartAxis(); |
| | | this.chartControl1.EndInit(); |
| | | _initial_data = true; |
| | | |
| | | } |
| | | |
| | | //是否是无效数据 |
| | |
| | | { |
| | | return true; |
| | | } |
| | | if (_series_pt == null) |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | #region Add Chart Data |
| | | |
| | | private void AddPointSeries(Color color, AxisXBase axis_x, AxisYBase axis_y, XYDiagramPaneBase pane, List<Yw.Geometry.Point2d> pt_list) |
| | | private Series AddPointSeries(Color color, AxisXBase axis_x, AxisYBase axis_y, XYDiagramPaneBase pane, List<Yw.Geometry.Point2d> pt_list) |
| | | { |
| | | if (pt_list == null || !pt_list.Any()) |
| | | return; |
| | | return null; |
| | | |
| | | var view = new DevExpress.XtraCharts.PointSeriesView(); |
| | | view.PointMarkerOptions.Size = 8; |
| | |
| | | series.CrosshairLabelPattern = "{A}"; |
| | | series.Points.AddRange(series_pt_list.ToArray()); |
| | | this.chartControl1.Series.Add(series); |
| | | |
| | | return series; |
| | | } |
| | | |
| | | private void AddLineSeries(Color color, AxisXBase axis_x, AxisYBase axis_y, XYDiagramPaneBase pane, List<Yw.Geometry.Point2d> pt_list, DashStyle dash = DashStyle.Solid) |
| | |
| | | #endregion Calc |
| | | |
| | | #region ChartEvent |
| | | |
| | | private SeriesPoint _pick_point = null;// 选中点 |
| | | |
| | | private int _pick_point_index = -1; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | var hitInfo = chartControl1.CalcHitInfo(e.Location); |
| | | _pick_point = null; |
| | | _pick_point_index = -1; |
| | | if (e.Button == MouseButtons.Left) |
| | | { |
| | | if (hitInfo.InSeriesPoint && hitInfo.SeriesPoint.Tag is int) |
| | | if (hitInfo.InSeriesPoint && hitInfo.SeriesPoint.Tag is int index) |
| | | { |
| | | _pick_point = hitInfo.SeriesPoint; |
| | | _pick_point_index = index; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private void chartControl1_MouseMove(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (IsInvalidData()) |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (_pick_point == null) |
| | | if (IsInvalidData()) |
| | | return; |
| | | var diagram_coordinates = _diagram.PointToDiagram(e.Location); |
| | | var axis_value = diagram_coordinates.GetAxisValue(_axis_y); |
| | | if (axis_value == null) |
| | | return; |
| | | _pick_point.Values[0] = axis_value.NumericalValue; |
| | | _pick_point.NumericalArgument = diagram_coordinates.NumericalArgument; |
| | | _series_pt.Points[_pick_point_index].Values[0] = axis_value.NumericalValue; |
| | | _series_pt.Points[_pick_point_index].NumericalArgument = diagram_coordinates.NumericalArgument; |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | if (_pick_point == null) |
| | | return; |
| | | if (_pick_point.Tag is not int index) |
| | | return; |
| | | var x = _pick_point.NumericalArgument; |
| | | var y = _pick_point.Values[0]; |
| | | SetPointPtValue(index, x, y); |
| | | |
| | | _pick_point = null; |
| | | return; |
| | | var x = _series_pt.Points[_pick_point_index].NumericalArgument; |
| | | var y = _series_pt.Points[_pick_point_index].Values[0]; |
| | | SetPointValue(_pick_point_index, x, y); |
| | | _pick_point_index = -1; |
| | | } |
| | | |
| | | |
| | | private void chartControl1_KeyUp(object sender, KeyEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | if (_mouse_mode) |
| | | return; |
| | | if (_pick_point == null) |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | double space_x = _coordinate.CoordSpaceX / 50; |
| | | double space_y = _coordinate.CoordSpaceY / 50; |
| | | double x = _pick_point.NumericalArgument; |
| | | double y = _pick_point.Values[0]; |
| | | double x = _series_pt.Points[_pick_point_index].NumericalArgument; |
| | | double y = _series_pt.Points[_pick_point_index].Values[0]; |
| | | if (e.KeyCode == Keys.Up) |
| | | { |
| | | y += space_y; |
| | |
| | | { |
| | | x += space_x; |
| | | } |
| | | _pick_point.Values[0] = y; |
| | | _pick_point.NumericalArgument = x; |
| | | var index = _pick_point.Tag.is |
| | | SetPointPtValue(); |
| | | SetPointValue(_pick_point_index, x, y); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新数据 |
| | | /// </summary> |
| | | private void SetPointPtValue(int index, double x, double y) |
| | | private void SetPointValue(int index, double x, double y) |
| | | { |
| | | if (IsInvalidData()) |
| | | return; |