How to create stock volume open high low close chart in Word document using C#?
Syncfusion Essential DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can create stock volume-open-high-low-close chart in Word document in C#.
What is a volume-open-high-low-close chart?
A volume-open-high-low-close stock market chart is a type of bar chart or graph used primarily to show changes in the value of tradable assets such as stocks over a given period.
Volume-Open-High-Low-Close chart in Word document
Steps to create volume-open-high-low-close chart in Word document:
Step 1: Initialize chart
Create a chart object by calling the paragraph.AppendChart(446,270) method.
C#
//Create and append the chart to the paragraph. WChart chart = paragraph.AppendChart(446, 270);
Step 2: Assign data, chart type and chart elements
Add the basic elements like the chart title, data labels, legend and specify the chart type to the OfficeChartType.Stock_VolumeOpenHighLowClose enum value.
- Assign data.
- Chart type.
- DataLabels via DefaultDataPoint
- ChartTitle of the chart object.
- Set TRUE to the chart’s HasLegend property to show the legend, else False.
C#
//Set region of Chart data. chart.DataRange = chart.ChartData[1, 1, 6, 6]; //Set chart type. chart.ChartType = OfficeChartType.Stock_VolumeOpenHighLowClose; //Set a chart title. chart.ChartTitle = "Volume-Open-High-Low-Close Surface Chart"; //Set legend. chart.HasLegend = true; chart.Legend.Position = OfficeLegendPosition.Bottom; //Set Datalabels. series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; series1.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = true; series1.SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle; series1.SerieFormat.MarkerBackgroundColorIndex = OfficeKnownColors.LightGreen; series1.SerieFormat.MarkerForegroundColorIndex = OfficeKnownColors.Black;
For creating a stock volume-open-high-low-close chart, the series count must be 5. The data range should be set before selecting the chart type.
Applicable properties to modify volume series in volume-open-high-low-close chart
Below is a list of other common properties applicable to modify volume series (chart.Series[0]) in volume-open-high-low-close chart:
Properties used to modify the markers in volume-open-high-low-close chart
Below is a list of properties that are used to change the markers in volume-open-high-low-close chart.
- MarkerBackgroundColor (or) MarkerBackgroundColorIndex
- MarkerForegroundColor (or) MarkerForegroundColorIndex
- MarkerSize
- MarkerStyle
- IsAutoMarkerNote:
- Marker properties are applicable for all open (chart.Series[1]), high (chart.Series[2]), low (chart.Series[3]) and close (chart.Series[4]) series.
- If close value (chart.Series[4]) is greater than open value (chart.Series[1]), then those are called Up-Bars and FirstDropBar property can be used to format them using DocIO.
- If close value (chart.Series[4] is less than open value (chart.Series[1]), then those are called Down-Bars and SecondDropBar property can be used to format them using DocIO.
The following C# code sample shows the creation of stock volume-open-high-low-close chart using the Word library.
C#
//Create a new Word document. using (WordDocument document = new WordDocument()) { //Add a section to the document. IWSection section = document.AddSection(); //Add a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); //Create and append the chart to the paragraph. WChart chart = paragraph.AppendChart(446, 270); //Set chart data. chart.ChartData.SetValue(1, 1, "Date"); chart.ChartData.SetValue(2, 1, "Volume"); chart.ChartData.SetValue(3, 1, "Open"); chart.ChartData.SetValue(4, 1, "High"); chart.ChartData.SetValue(5, 1, "Low"); chart.ChartData.SetValue(6, 1, "Close"); chart.ChartData.SetValue(1, 2, "1-Apr-17"); chart.ChartData.SetValue(2, 2, 10000); chart.ChartData.SetValue(3, 2, 30); chart.ChartData.SetValue(4, 2, 50); chart.ChartData.SetValue(5, 2, 10); chart.ChartData.SetValue(6, 2, 40); chart.ChartData.SetValue(1, 3, "2-Apr-17"); chart.ChartData.SetValue(2, 3, 20000); chart.ChartData.SetValue(3, 3, 40); chart.ChartData.SetValue(4, 3, 60); chart.ChartData.SetValue(5, 3, 20); chart.ChartData.SetValue(6, 3, 30); chart.ChartData.SetValue(1, 4, "3-Apr-17"); chart.ChartData.SetValue(2, 4, 30000); chart.ChartData.SetValue(3, 4, 35); chart.ChartData.SetValue(4, 4, 55); chart.ChartData.SetValue(5, 4, 15); chart.ChartData.SetValue(6, 4, 45); chart.ChartData.SetValue(1, 5, "4-Apr-17"); chart.ChartData.SetValue(2, 5, 25000); chart.ChartData.SetValue(3, 5, 45); chart.ChartData.SetValue(4, 5, 65); chart.ChartData.SetValue(5, 5, 25); chart.ChartData.SetValue(6, 5, 35); chart.ChartData.SetValue(1, 6, "5-Apr-17"); chart.ChartData.SetValue(2, 6, 15000); chart.ChartData.SetValue(3, 6, 50); chart.ChartData.SetValue(4, 6, 70); chart.ChartData.SetValue(5, 6, 30); chart.ChartData.SetValue(6, 6, 60); //Set region of Chart data. chart.DataRange = chart.ChartData[1, 1, 6, 6]; //Set chart series in the column for assigned data region. chart.IsSeriesInRows = true; //Set chart type. chart.ChartType = OfficeChartType.Stock_VolumeOpenHighLowClose; //Set a Chart Title. chart.ChartTitle = "Volume-Open-High-Low-Close Chart"; //Set primary category axis. chart.PrimaryCategoryAxis.NumberFormat = "dd-MMM-yy"; //Set Datalabels. IOfficeChartSerie series1 = chart.Series[1]; IOfficeChartSerie series2 = chart.Series[2]; IOfficeChartSerie series3 = chart.Series[3]; IOfficeChartSerie series4 = chart.Series[4]; series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; series1.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = true; series1.SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle; series1.SerieFormat.MarkerBackgroundColorIndex = OfficeKnownColors.LightGreen; series1.SerieFormat.MarkerForegroundColorIndex = OfficeKnownColors.Black; series2.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; series2.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = true; series2.SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle; series2.SerieFormat.MarkerBackgroundColorIndex = OfficeKnownColors.Red; series2.SerieFormat.MarkerForegroundColorIndex = OfficeKnownColors.Black; series3.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; series3.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = true; series3.SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle; series3.SerieFormat.MarkerBackgroundColorIndex = OfficeKnownColors.Light_yellow; series3.SerieFormat.MarkerForegroundColorIndex = OfficeKnownColors.Black; series4.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; series4.DataPoints.DefaultDataPoint.DataLabels.IsSeriesName = true; series4.SerieFormat.MarkerStyle = OfficeChartMarkerType.Circle; series4.SerieFormat.MarkerBackgroundColorIndex = OfficeKnownColors.Lavender; series4.SerieFormat.MarkerForegroundColorIndex = OfficeKnownColors.Black; //Set legend. chart.HasLegend = true; chart.Legend.Position = OfficeLegendPosition.Bottom; //Create a file stream. using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Sample.docx"), FileMode.Create, FileAccess.ReadWrite)) { //Save the Word document to the file stream. document.Save(outputFileStream, FormatType.Docx); } }
A complete working sample of how to create volume-open-high-low-close chart in Word document in C# can be downloaded from GitHub.
Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail merge, merge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.
Explore more about the rich set of Syncfusion Word Framework features and an online example to create a chart in a Word document.
Conclusion
I hope you enjoyed learning about how to create stock volume open high low close chart in Word document using C#.
You can refer to our .NET Core Word library’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET Core Word library example to understand how to present and manipulate data.
For current customers, you can check out our .NET Core components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET Core Word library and other .NET Core components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!