Crear Gráfico de Cotizaciones Apertura Alta Baja Cierre (OHLC)

Escenarios de uso posibles

El gráfico de cotizaciones apertura-alta-baja-cierre (OHLC) utiliza cinco columnas de datos, en orden: categoría, apertura, alta, baja y cierre. El rango de precios en cada categoría nuevamente se indica con una línea vertical, mientras que el rango entre la apertura y el cierre se muestra con una barra flotante más ancha; si el precio aumenta en la categoría (el cierre es mayor que la apertura), la barra se llena de un color, mientras que si el precio disminuye, la barra se llena de otro. Este tipo de gráfico a menudo se llama gráfico de velas.

todo:image_alt_text

todo:image_alt_text

Mejoras de visibilidad en el gráfico

A menudo usamos colores en lugar de blanco y negro para indicar precios crecientes y decrecientes. En el primer conjunto de velas a continuación, el rojo muestra precios crecientes y el verde precios decrecientes.

todo:image_alt_text

Código de muestra

El siguiente código de muestra carga el archivo de Excel de ejemplo y genera el archivo de Excel de salida.

// 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");