|  | 
|  | 1 | +using System; | 
|  | 2 | +using System.Collections.Generic; | 
|  | 3 | +using System.ComponentModel; | 
|  | 4 | +using System.Data; | 
|  | 5 | +using System.Drawing; | 
|  | 6 | +using System.Linq; | 
|  | 7 | +using System.Text; | 
|  | 8 | +using System.Threading.Tasks; | 
|  | 9 | +using System.Windows.Forms; | 
|  | 10 | + | 
|  | 11 | +namespace OxyPlotQuickstart | 
|  | 12 | +{ | 
|  | 13 | +    public partial class Form1 : Form | 
|  | 14 | +    { | 
|  | 15 | +        public Form1() | 
|  | 16 | +        { | 
|  | 17 | +            InitializeComponent(); | 
|  | 18 | +            ScatterButton_Click(null, null); | 
|  | 19 | +        } | 
|  | 20 | + | 
|  | 21 | +        private Random rand = new Random(0); | 
|  | 22 | +        private double[] RandomWalk(int points = 5, double start = 100, double mult = 50) | 
|  | 23 | +        { | 
|  | 24 | +            // return an array of difting random numbers | 
|  | 25 | +            double[] values = new double[points]; | 
|  | 26 | +            values[0] = start; | 
|  | 27 | +            for (int i = 1; i < points; i++) | 
|  | 28 | +                values[i] = values[i - 1] + (rand.NextDouble() - .5) * mult; | 
|  | 29 | +            return values; | 
|  | 30 | +        } | 
|  | 31 | + | 
|  | 32 | +        private double[] Consecutive(int pointCount = 5) | 
|  | 33 | +        { | 
|  | 34 | +            // return an array of consecutive numbers starting at 1 | 
|  | 35 | +            double[] values = new double[pointCount]; | 
|  | 36 | +            for (int i = 0; i < pointCount; i++) | 
|  | 37 | +                values[i] = i + 1; | 
|  | 38 | +            return values; | 
|  | 39 | +        } | 
|  | 40 | + | 
|  | 41 | +        private void BarButton_Click(object sender, EventArgs e) | 
|  | 42 | +        { | 
|  | 43 | +            // generate some random Y data | 
|  | 44 | +            int pointCount = 5; | 
|  | 45 | +            double[] ys1 = RandomWalk(pointCount); | 
|  | 46 | +            double[] ys2 = RandomWalk(pointCount); | 
|  | 47 | + | 
|  | 48 | +            // create a series of bars and populate them with data | 
|  | 49 | +            var seriesA = new OxyPlot.Series.ColumnSeries() | 
|  | 50 | +            { | 
|  | 51 | +                Title = "Series A", | 
|  | 52 | +                StrokeColor = OxyPlot.OxyColors.Black, | 
|  | 53 | +                FillColor = OxyPlot.OxyColors.Red, | 
|  | 54 | +                StrokeThickness = 1 | 
|  | 55 | +            }; | 
|  | 56 | + | 
|  | 57 | +            var seriesB = new OxyPlot.Series.ColumnSeries() | 
|  | 58 | +            { | 
|  | 59 | +                Title = "Series B", | 
|  | 60 | +                StrokeColor = OxyPlot.OxyColors.Black, | 
|  | 61 | +                FillColor = OxyPlot.OxyColors.Blue, | 
|  | 62 | +                StrokeThickness = 1 | 
|  | 63 | +            }; | 
|  | 64 | + | 
|  | 65 | +            for (int i = 0; i < pointCount; i++) | 
|  | 66 | +            { | 
|  | 67 | +                seriesA.Items.Add(new OxyPlot.Series.ColumnItem(ys1[i], i)); | 
|  | 68 | +                seriesB.Items.Add(new OxyPlot.Series.ColumnItem(ys2[i], i)); | 
|  | 69 | +            } | 
|  | 70 | + | 
|  | 71 | +            // create a model and add the bars into it | 
|  | 72 | +            var model = new OxyPlot.PlotModel | 
|  | 73 | +            { | 
|  | 74 | +                Title = "Bar Graph (Column Series)" | 
|  | 75 | +            }; | 
|  | 76 | +            model.Axes.Add(new OxyPlot.Axes.CategoryAxis()); | 
|  | 77 | +            model.Series.Add(seriesA); | 
|  | 78 | +            model.Series.Add(seriesB); | 
|  | 79 | + | 
|  | 80 | +            // load the model into the user control | 
|  | 81 | +            plotView1.Model = model; | 
|  | 82 | +        } | 
|  | 83 | + | 
|  | 84 | +        private void ScatterButton_Click(object sender, EventArgs e) | 
|  | 85 | +        { | 
|  | 86 | +            // generate some random XY data | 
|  | 87 | +            int pointCount = 1_000; | 
|  | 88 | +            double[] xs1 = RandomWalk(pointCount); | 
|  | 89 | +            double[] ys1 = RandomWalk(pointCount); | 
|  | 90 | +            double[] xs2 = RandomWalk(pointCount); | 
|  | 91 | +            double[] ys2 = RandomWalk(pointCount); | 
|  | 92 | + | 
|  | 93 | +            // create lines and fill them with data points | 
|  | 94 | +            var line1 = new OxyPlot.Series.LineSeries() | 
|  | 95 | +            { | 
|  | 96 | +                Title = $"Series 1", | 
|  | 97 | +                Color = OxyPlot.OxyColors.Blue, | 
|  | 98 | +                StrokeThickness = 1, | 
|  | 99 | +                MarkerSize = 2, | 
|  | 100 | +                MarkerType = OxyPlot.MarkerType.Circle | 
|  | 101 | +            }; | 
|  | 102 | + | 
|  | 103 | +            var line2 = new OxyPlot.Series.LineSeries() | 
|  | 104 | +            { | 
|  | 105 | +                Title = $"Series 2", | 
|  | 106 | +                Color = OxyPlot.OxyColors.Red, | 
|  | 107 | +                StrokeThickness = 1, | 
|  | 108 | +                MarkerSize = 2, | 
|  | 109 | +                MarkerType = OxyPlot.MarkerType.Circle | 
|  | 110 | +            }; | 
|  | 111 | + | 
|  | 112 | +            for (int i = 0; i < pointCount; i++) | 
|  | 113 | +            { | 
|  | 114 | +                line1.Points.Add(new OxyPlot.DataPoint(xs1[i], ys1[i])); | 
|  | 115 | +                line2.Points.Add(new OxyPlot.DataPoint(xs2[i], ys2[i])); | 
|  | 116 | +            } | 
|  | 117 | + | 
|  | 118 | +            // create the model and add the lines to it | 
|  | 119 | +            var model = new OxyPlot.PlotModel | 
|  | 120 | +            { | 
|  | 121 | +                Title = $"Scatter Plot ({pointCount:N0} points each)" | 
|  | 122 | +            }; | 
|  | 123 | +            model.Series.Add(line1); | 
|  | 124 | +            model.Series.Add(line2); | 
|  | 125 | + | 
|  | 126 | +            // load the model into the user control | 
|  | 127 | +            plotView1.Model = model; | 
|  | 128 | +        } | 
|  | 129 | + | 
|  | 130 | +        private void LineButton_Click(object sender, EventArgs e) | 
|  | 131 | +        { | 
|  | 132 | +            // generate some random Y data | 
|  | 133 | +            int pointCount = 1000_000; | 
|  | 134 | +            double[] xs = Consecutive(pointCount); | 
|  | 135 | +            double[] ys1 = RandomWalk(pointCount); | 
|  | 136 | +            double[] ys2 = RandomWalk(pointCount); | 
|  | 137 | + | 
|  | 138 | +            // create lines and fill them with data points | 
|  | 139 | +            var line1 = new OxyPlot.Series.LineSeries() | 
|  | 140 | +            { | 
|  | 141 | +                Title = $"Series 1", | 
|  | 142 | +                Color = OxyPlot.OxyColors.Blue, | 
|  | 143 | +                StrokeThickness = 1, | 
|  | 144 | +            }; | 
|  | 145 | + | 
|  | 146 | +            var line2 = new OxyPlot.Series.LineSeries() | 
|  | 147 | +            { | 
|  | 148 | +                Title = $"Series 2", | 
|  | 149 | +                Color = OxyPlot.OxyColors.Red, | 
|  | 150 | +                StrokeThickness = 1, | 
|  | 151 | +            }; | 
|  | 152 | + | 
|  | 153 | +            for (int i = 0; i < pointCount; i++) | 
|  | 154 | +            { | 
|  | 155 | +                line1.Points.Add(new OxyPlot.DataPoint(xs[i], ys1[i])); | 
|  | 156 | +                line2.Points.Add(new OxyPlot.DataPoint(xs[i], ys2[i])); | 
|  | 157 | +            } | 
|  | 158 | + | 
|  | 159 | +            // create the model and add the lines to it | 
|  | 160 | +            var model = new OxyPlot.PlotModel | 
|  | 161 | +            { | 
|  | 162 | +                Title = $"Line Plot ({pointCount:N0} points each)" | 
|  | 163 | +            }; | 
|  | 164 | +            model.Series.Add(line1); | 
|  | 165 | +            model.Series.Add(line2); | 
|  | 166 | + | 
|  | 167 | +            // load the model into the user control | 
|  | 168 | +            plotView1.Model = model; | 
|  | 169 | +        } | 
|  | 170 | +    } | 
|  | 171 | +} | 
0 commit comments