Créer un graphique boursier Open High Low Close (OHLC)
Scénarios d’utilisation possibles
Le graphique Open-High-Low-Close (OHLC) utilise cinq colonnes de données, dans l’ordre : catégorie, ouverture, haut, bas et clôture. La plage de prix dans chaque catégorie est à nouveau indiquée par une ligne verticale, tandis que la plage entre l’ouverture et la clôture est donnée par une barre flottante plus large ; si le prix augmente dans la catégorie (la clôture est supérieure à l’ouverture), la barre est remplie d’une couleur, tandis que si le prix diminue, la barre est remplie d’une autre couleur. Ce type de graphique est souvent appelé un graphique en chandelier.
Améliorations de la visibilité dans le graphique
Nous utilisons souvent des couleurs plutôt que du noir et blanc pour indiquer les prix croissants et décroissants. Dans le premier ensemble de chandeliers ci-dessous, le rouge montre les prix croissants et le vert les prix décroissants.
Code d’exemple
Le code d’exemple suivant charge le fichier Excel d’exemple et génère le fichier Excel de sortie.
// 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"); |