OHLC(始値 高値 安値 終値)株価チャートの作成
Contents
[
Hide
]
可能な使用シナリオ
Open-High-Low-Close(OHLC)チャートは、カテゴリ、オープン、ハイ、ロー、クローズのデータを使用し、価格の範囲は垂直線で示され、オープンからクローズまでの範囲はより広い浮動バーで示されます。カテゴリ内で価格が上昇する場合(クローズがオープンより高い場合)、バーは1つの色で塗りつぶされ、価格が下落する場合は別の色で塗りつぶされます。この種のチャートは、ローソク足チャートと呼ばれることがよくあります。
チャートの可視性の改善
価格の増減を示す際に、通常は白黒の代わりに色を使用します。最初のローソク足チャートでは、赤が増加を示し、緑が減少を示します。
サンプルコード
サンプルExcelファイルを読み込み、出力Excelファイルを生成するサンプルコードは、以下の通りです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Workbook | |
Workbook workbook = new Workbook("Open-High-Low-Close.xlsx"); | |
// Access the first worksheet. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
//Create High-Low-Close-Stock Chart | |
int pieIdx = worksheet.Charts.Add(ChartType.StockOpenHighLowClose, 5, 6, 20, 12); | |
// Retrieve the Chart object | |
Chart chart = worksheet.Charts[pieIdx]; | |
// Set the legend can be showed | |
chart.ShowLegend = true; | |
// Set the chart title name | |
chart.Title.Text = "OPen-High-Low-Close Stock"; | |
// Set the Legend at the bottom of the chart area | |
chart.Legend.Position = LegendPositionType.Bottom; | |
// Set data range | |
chart.SetChartDataRange("A1:E9", true); | |
// Set category data | |
chart.NSeries.CategoryData = "A2:A9"; | |
// Set the DownBars and UpBars with different color | |
chart.NSeries[0].DownBars.Area.ForegroundColor = Color.Green; | |
chart.NSeries[0].UpBars.Area.ForegroundColor = Color.Red; | |
// Fill the PlotArea area with nothing | |
chart.PlotArea.Area.FillFormat.FillType = FillType.None; | |
// Save the Excel file | |
workbook.Save("out.xlsx"); |