From 6ee5c3b045fd5dcde271b954a07a348a076bda1e Mon Sep 17 00:00:00 2001 From: Scott W Harden Date: Sat, 27 Jul 2019 10:21:31 -0400 Subject: [PATCH] add finance demos to cookbook --- .gitignore | 4 +++ demos/ScottPlotCookbook/CookBookManager.cs | 4 +++ demos/ScottPlotCookbook/Recipes.cs | 38 ++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/.gitignore b/.gitignore index f4acacf65f..47054b8213 100644 --- a/.gitignore +++ b/.gitignore @@ -288,3 +288,7 @@ __pycache__/ *.btm.cs *.odx.cs *.xsd.cs +doc/cookbook/images/30_Signal.png +doc/cookbook/images/31_Signal_With_Antialiasing_Off.png +doc/cookbook/images/31_Signal_With_Antialiasing_Off.png +doc/cookbook/images/30_Signal.png diff --git a/demos/ScottPlotCookbook/CookBookManager.cs b/demos/ScottPlotCookbook/CookBookManager.cs index de1eb705b2..c2f7b8b9c7 100644 --- a/demos/ScottPlotCookbook/CookBookManager.cs +++ b/demos/ScottPlotCookbook/CookBookManager.cs @@ -75,6 +75,8 @@ public void GenerateAllFigures(int width, int height, string outputFolderName = hashes.Add(recipies.Figure_64_Manual_Grid_Spacing()); hashes.Add(recipies.Figure_65_Histogram()); hashes.Add(recipies.Figure_66_CPH()); + hashes.Add(recipies.Figure_67_Candlestick()); + hashes.Add(recipies.Figure_68_OHLC()); ValidateImageHashes(hashes.ToArray()); @@ -193,6 +195,8 @@ public void ValidateImageHashes(string[] hashLines) knownHahes += "DCC984120C142F91AF13438641BC15FE 64_Manual_Grid_Spacing()\n"; knownHahes += "7789995EFF9D69CB6132AEEDC8083687 65_Histogram()\n"; knownHahes += "F3A1F0FC4E0027E0DDE4B6950DF3B534 66_CPH()\n"; + knownHahes += "79698A6E3CC91FDD36810332C05C58D9 67_Candlestick()\n"; + knownHahes += "8DA76CAA67E3AB76C70E63F48B7ABCE6 68_OHLC()\n"; string hashCodeNeeded = ""; diff --git a/demos/ScottPlotCookbook/Recipes.cs b/demos/ScottPlotCookbook/Recipes.cs index 8d2763579f..9676f773a0 100644 --- a/demos/ScottPlotCookbook/Recipes.cs +++ b/demos/ScottPlotCookbook/Recipes.cs @@ -822,5 +822,43 @@ public string Figure_66_CPH() Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); return name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()); } + + public string Figure_67_Candlestick() + { + string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", ""); + string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png"); + + Random rand = new Random(0); + int pointCount = 60; + ScottPlot.OHLC[] ohlcs = ScottPlot.DataGen.RandomStockPrices(rand, pointCount); + + var plt = new ScottPlot.Plot(width, height); + plt.Title("Candlestick Chart"); + plt.YLabel("Stock Price (USD)"); + plt.XLabel("Day (into Q4)"); + plt.PlotCandlestick(ohlcs); + plt.SaveFig(fileName); + Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); + return name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()); + } + + public string Figure_68_OHLC() + { + string name = System.Reflection.MethodBase.GetCurrentMethod().Name.Replace("Figure_", ""); + string fileName = System.IO.Path.GetFullPath($"{outputFolderName}/{name}.png"); + + Random rand = new Random(0); + int pointCount = 60; + ScottPlot.OHLC[] ohlcs = ScottPlot.DataGen.RandomStockPrices(rand, pointCount); + + var plt = new ScottPlot.Plot(width, height); + plt.Title("Open/High/Low/Close (OHLC) Chart"); + plt.YLabel("Stock Price (USD)"); + plt.XLabel("Day (into Q4)"); + plt.PlotOHLC(ohlcs); + plt.SaveFig(fileName); + Console.WriteLine($"Saved: {System.IO.Path.GetFileName(fileName)}"); + return name + ":" + ScottPlot.Tools.BitmapHash(plt.GetBitmap()); + } } }