Create Open-High-Low-Close(OHLC) Stock Chart

Possible Usage Scenarios

The Open-High-Low-Close (OHLC) chart uses five columns of data, in order: category, open, high, low, and close. The range of prices in each category is again indicated by a vertical line, while the range between open and close is given by a wider floating bar; if the price increases in the category (close is higher than open), the bar is filled with one color, while if the price decreases, the bar is filled with another. This type of chart is often called a candlestick chart.

todo:image_alt_text

todo:image_alt_text

Visibility improvements in the chart

We often use colors rather than black and white to indicate increasing and decreasing prices. In the first set of candlesticks below, red shows increasing nad green decreasing prices.

todo:image_alt_text

Sample Code

The following sample code loads the sample Excel file and generates the output Excel file.

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