Create Volume-Open-High-Low-Close Stock Charts via C#
Native and high performance MS Excel Charts creation programmatically using server side .NET APIs.
How to Create Volume-Open-High-Low-Close Stock Charts via C#
It is easy for the developers to create a Volume-Open-High-Low-Close Stock chart within running different reporting applications for data processing in just a few lines of code.
- Include the namespace in your class file
- Create Workbook class instance by sample Excel file .
- Add a Volume-Open-High-Low-Close Stock Chart to the worksheet by calling the Charts collection’s Add method, encapsulated in the Worksheet object.
- Access the new Chart object from the Charts collection by passing its index.
- Set the chart’s data source with Chart.SetChartDataRange method.
- Set category data with CategoryData property.
- Save as Excel or ODS Output file .
System Requirements
Just make sure that system have Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Windows Azure, Mono or Xamarin Platforms as well as development environment like Microsoft Visual Studio.
- Install from command line asnuget install Aspose.Cells
or via Package Manager Console of Visual Studio with Install-Package Aspose.Cells
.
- Alternatively, get the offline MSI installer or all DLLs in a ZIP file from downloadsFollowing source code shows how to create a Volume-Open-High-Low-Close Stock Chart to MS Excel XLSX file using C#.
// Create an instance of Workbook | |
Workbook workbook = new Workbook("Volume-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.StockVolumeOpenHighLowClose, 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 = "Volume-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:F9", true); | |
// Set category data | |
chart.NSeries.CategoryData = "A2:A9"; | |
// Set Color for the first series(Volume) data | |
chart.NSeries[0].Area.ForegroundColor = Color.FromArgb(79, 129,189); | |
// Fill the PlotArea area with nothing | |
chart.PlotArea.Area.FillFormat.FillType = FillType.None; | |
// Save the Excel file | |
workbook.Save("out.xlsx"); |