예제 #1
0
        private void GenerateNewData()
        {
            Random rand = new Random();

            int pointCount = 100;

            ScottPlot.OHLC[] ohlcs      = new ScottPlot.OHLC[pointCount];
            double[]         timestamps = new double[pointCount];
            double[]         volumes    = new double[pointCount];
            for (int i = 0; i < ohlcs.Length; i++)
            {
                double open  = rand.NextDouble() * 10 + 50;
                double close = rand.NextDouble() * 10 + 50;
                double high  = Math.Max(open, close) + rand.NextDouble() * 10;
                double low   = Math.Min(open, close) - rand.NextDouble() * 10;
                ohlcs[i]      = new ScottPlot.OHLC(open, high, low, close, i);
                timestamps[i] = i;
                volumes[i]    = 1000 + rand.NextDouble() * 500;
            }

            scottPlotUC1.plt.Clear();
            scottPlotUC1.plt.YLabel("Share Price", fontSize: 10);
            scottPlotUC1.plt.Title("ScottPlot Candlestick Demo");
            scottPlotUC1.plt.PlotOHLC(ohlcs);
            scottPlotUC1.plt.AxisAuto();
            scottPlotUC1.Render();

            scottPlotUC2.plt.Clear();
            scottPlotUC2.plt.YLabel("Volume", fontSize: 10);
            scottPlotUC2.plt.PlotBar(timestamps, volumes, barWidth: .5);
            scottPlotUC2.plt.AxisAuto(.01, .1);
            scottPlotUC2.plt.Axis(null, null, 0, null);
            scottPlotUC2.Render();
        }
예제 #2
0
        public void Test_Candle_SetWidth()
        {
            var ohlcs = new ScottPlot.OHLC[]
            {
                // open, high, low, close, time, timeSpan
                new ScottPlot.OHLC(273, 275, 264, 265, 1, 1),
                new ScottPlot.OHLC(267, 276, 265, 274, 2.5, 2),
                new ScottPlot.OHLC(277, 280, 275, 278, 4, 1),
            };

            var plt = new ScottPlot.Plot(400, 300);

            plt.Grid(false);
            plt.PlotCandlestick(ohlcs, autoWidth: false);
            plt.SetAxisLimits(xMin: -1, xMax: 5);
            TestTools.SaveFig(plt);
        }
예제 #3
0
        public void Test_Candle_CustomColors()
        {
            var ohlcs = new ScottPlot.OHLC[]
            {
                // open, high, low, close, time, timeSpan
                new ScottPlot.OHLC(273, 275, 264, 265, 1, 1),
                new ScottPlot.OHLC(267, 276, 265, 274, 2.5, 2),
                new ScottPlot.OHLC(277, 280, 275, 278, 4, 1),
            };

            var colorUp   = System.Drawing.ColorTranslator.FromHtml("#9926a69a");
            var colorDown = System.Drawing.ColorTranslator.FromHtml("#99ef5350");

            var plt     = new ScottPlot.Plot(400, 300);
            var candles = plt.AddCandlesticks(ohlcs);

            candles.ColorUp   = colorUp;
            candles.ColorDown = colorDown;
            plt.SetAxisLimits(xMin: -1, xMax: 5);
            TestTools.SaveFig(plt);
        }