|  | 
|  | 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 ZedGraphQuickstart | 
|  | 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, 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 points) | 
|  | 33 | +        { | 
|  | 34 | +            // return an array of ascending numbers starting at 1 | 
|  | 35 | +            double[] values = new double[points]; | 
|  | 36 | +            for (int i = 0; i < points; i++) | 
|  | 37 | +                values[i] = i; | 
|  | 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[] xs = Consecutive(pointCount); | 
|  | 46 | +            double[] ys1 = RandomWalk(pointCount); | 
|  | 47 | +            double[] ys2 = RandomWalk(pointCount); | 
|  | 48 | + | 
|  | 49 | +            // clear old curves | 
|  | 50 | +            zedGraphControl1.GraphPane.CurveList.Clear(); | 
|  | 51 | + | 
|  | 52 | +            // plot the data as bars | 
|  | 53 | +            zedGraphControl1.GraphPane.AddBar("Group A", xs, ys1, Color.Blue); | 
|  | 54 | +            zedGraphControl1.GraphPane.AddBar("Group B", xs, ys2, Color.Red); | 
|  | 55 | + | 
|  | 56 | +            // style the plot | 
|  | 57 | +            zedGraphControl1.GraphPane.Title.Text = $"Bar Plot ({pointCount:n0} points)"; | 
|  | 58 | +            zedGraphControl1.GraphPane.XAxis.Title.Text = "Horizontal Axis Label"; | 
|  | 59 | +            zedGraphControl1.GraphPane.YAxis.Title.Text = "Vertical Axis Label"; | 
|  | 60 | + | 
|  | 61 | +            // auto-axis and update the display | 
|  | 62 | +            zedGraphControl1.GraphPane.XAxis.ResetAutoScale(zedGraphControl1.GraphPane, CreateGraphics()); | 
|  | 63 | +            zedGraphControl1.GraphPane.YAxis.ResetAutoScale(zedGraphControl1.GraphPane, CreateGraphics()); | 
|  | 64 | +            zedGraphControl1.Refresh(); | 
|  | 65 | +        } | 
|  | 66 | + | 
|  | 67 | +        private void ScatterButton_Click(object sender, EventArgs e) | 
|  | 68 | +        { | 
|  | 69 | +            // generate some random Y data | 
|  | 70 | +            int pointCount = 100; | 
|  | 71 | +            double[] xs1 = RandomWalk(pointCount); | 
|  | 72 | +            double[] ys1 = RandomWalk(pointCount); | 
|  | 73 | +            double[] xs2 = RandomWalk(pointCount); | 
|  | 74 | +            double[] ys2 = RandomWalk(pointCount); | 
|  | 75 | + | 
|  | 76 | +            // clear old curves | 
|  | 77 | +            zedGraphControl1.GraphPane.CurveList.Clear(); | 
|  | 78 | + | 
|  | 79 | +            // plot the data as curves | 
|  | 80 | +            var curve1 = zedGraphControl1.GraphPane.AddCurve("Series A", xs1, ys1, Color.Blue); | 
|  | 81 | +            curve1.Line.IsAntiAlias = true; | 
|  | 82 | + | 
|  | 83 | +            var curve2 = zedGraphControl1.GraphPane.AddCurve("Series B", xs2, ys2, Color.Red); | 
|  | 84 | +            curve2.Line.IsAntiAlias = true; | 
|  | 85 | + | 
|  | 86 | +            // style the plot | 
|  | 87 | +            zedGraphControl1.GraphPane.Title.Text = $"Scatter Plot ({pointCount:n0} points)"; | 
|  | 88 | +            zedGraphControl1.GraphPane.XAxis.Title.Text = "Horizontal Axis Label"; | 
|  | 89 | +            zedGraphControl1.GraphPane.YAxis.Title.Text = "Vertical Axis Label"; | 
|  | 90 | + | 
|  | 91 | +            // auto-axis and update the display | 
|  | 92 | +            zedGraphControl1.GraphPane.XAxis.ResetAutoScale(zedGraphControl1.GraphPane, CreateGraphics()); | 
|  | 93 | +            zedGraphControl1.GraphPane.YAxis.ResetAutoScale(zedGraphControl1.GraphPane, CreateGraphics()); | 
|  | 94 | +            zedGraphControl1.Refresh(); | 
|  | 95 | +        } | 
|  | 96 | + | 
|  | 97 | +        private void LineButton_Click(object sender, EventArgs e) | 
|  | 98 | +        { | 
|  | 99 | +            // generate some random Y data | 
|  | 100 | +            int pointCount = 100_000; | 
|  | 101 | +            double[] xs = Consecutive(pointCount); | 
|  | 102 | +            double[] ys1 = RandomWalk(pointCount); | 
|  | 103 | +            double[] ys2 = RandomWalk(pointCount); | 
|  | 104 | + | 
|  | 105 | +            // clear old curves | 
|  | 106 | +            zedGraphControl1.GraphPane.CurveList.Clear(); | 
|  | 107 | + | 
|  | 108 | +            // plot the data as curves | 
|  | 109 | +            var curve1 = zedGraphControl1.GraphPane.AddCurve("Series A", xs, ys1, Color.Blue); | 
|  | 110 | +            curve1.Line.IsAntiAlias = true; | 
|  | 111 | +            curve1.Symbol.IsVisible = false; | 
|  | 112 | + | 
|  | 113 | +            var curve2 = zedGraphControl1.GraphPane.AddCurve("Series B", xs, ys2, Color.Red); | 
|  | 114 | +            curve2.Line.IsAntiAlias = true; | 
|  | 115 | +            curve2.Symbol.IsVisible = false; | 
|  | 116 | + | 
|  | 117 | +            // style the plot | 
|  | 118 | +            zedGraphControl1.GraphPane.Title.Text = $"Scatter Plot ({pointCount:n0} points)"; | 
|  | 119 | +            zedGraphControl1.GraphPane.XAxis.Title.Text = "Horizontal Axis Label"; | 
|  | 120 | +            zedGraphControl1.GraphPane.YAxis.Title.Text = "Vertical Axis Label"; | 
|  | 121 | + | 
|  | 122 | +            // auto-axis and update the display | 
|  | 123 | +            zedGraphControl1.GraphPane.XAxis.ResetAutoScale(zedGraphControl1.GraphPane, CreateGraphics()); | 
|  | 124 | +            zedGraphControl1.GraphPane.YAxis.ResetAutoScale(zedGraphControl1.GraphPane, CreateGraphics()); | 
|  | 125 | +            zedGraphControl1.Refresh(); | 
|  | 126 | +        } | 
|  | 127 | +    } | 
|  | 128 | +} | 
0 commit comments