duheng
2024-09-19 d88ae862d5eda101f20385f3e34a2d7e6f9d3471
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using DevExpress.XtraCharts;
using Yw.WinFrmUI.Phart;
 
namespace HStation.WinFrmUI
{
    public partial class PerformChart : DevExpress.XtraEditors.XtraForm
    {
        public PerformChart()
        {
            InitializeComponent();
            this.chartControl1.SetChartBackColor();
        }
 
        public class DataPoint
        {
            public DataPoint(double x, double y)
            {
                X = x;
                Y = y;
            }
 
            public double X { get; set; }
            public double Y { get; set; }
        }
 
        public void SetBindingData(List<DataPoint> dataPoint, string xTitle = "X轴", string yTitle = "Y轴")
        {
            var series = this.chartControl1.GetSeriesByName("SeriesPoint");
            series.DataSource = dataPoint;
            series.ArgumentScaleType = ScaleType.Numerical;
            series.ArgumentDataMember = "X";
            series.ValueScaleType = ScaleType.Numerical;
            series.ValueDataMembers.AddRange(new string[] { "Y" });
            chartControl1.Series.Add(series);
            XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
            //X轴
            diagram.AxisX.Title.Visible = true;
            diagram.AxisX.Title.Text = xTitle;
            diagram.AxisX.Title.TextColor = Color.DodgerBlue;
            diagram.AxisX.Label.TextColor = Color.DodgerBlue;
            diagram.AxisX.Title.Font = new Font("Tahoma", 12, FontStyle.Regular);
            //Y轴
            diagram.AxisY.Title.Visible = true;
            diagram.AxisY.Title.Text = yTitle;
            diagram.AxisY.Title.TextColor = Color.Crimson;
            diagram.AxisY.Label.TextColor = Color.Crimson;
            diagram.AxisY.Title.Font = new Font("Tahoma", 12, FontStyle.Regular);
        }
    }
}