Articles in this section
Category / Section

How to create stock high low close chart in Word document using C#?

3 mins read

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 high-low-close chart in Word document in C#.

What is a high-low-close chart?

A high-low-close chart is a type of chart typically used to illustrate movements in the price of a financial instrument over time. Each vertical line on the chart shows the price range over one unit of time.

High low close chart

High-Low-Close chart in Word document

Steps to create 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_HighLowClose 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, 4, 6];
 
//Set chart type.
chart.ChartType = OfficeChartType.Stock_HighLowClose;
 
//Set a chart title.
chart.ChartTitle = "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;
series3.SerieFormat.LineProperties.LinePattern = OfficeChartLinePattern.Solid;
series3.SerieFormat.LineProperties.LineColor = Color.Black;

 

Note:

For creating a stock high-low-close chart, the series count must be 3. The data range should be set before selecting the chart type.

Properties used to modify the markers in high-low-close chart

Below is a list of properties that are used to change the markers in high-low-close chart.

The following C# code sample shows the creation of stock 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, "High");
    chart.ChartData.SetValue(3, 1, "Low");
    chart.ChartData.SetValue(4, 1, "Close");
    chart.ChartData.SetValue(1, 2, "1-Apr-17");
    chart.ChartData.SetValue(2, 2, 50);
    chart.ChartData.SetValue(3, 2, 10);
    chart.ChartData.SetValue(4, 2, 40);
    chart.ChartData.SetValue(1, 3, "2-Apr-17");
    chart.ChartData.SetValue(2, 3, 60);
    chart.ChartData.SetValue(3, 3, 20);
    chart.ChartData.SetValue(4, 3, 30);
    chart.ChartData.SetValue(1, 4, "3-Apr-17");
    chart.ChartData.SetValue(2, 4, 55);
    chart.ChartData.SetValue(3, 4, 15);
    chart.ChartData.SetValue(4, 4, 45);
    chart.ChartData.SetValue(1, 5, "4-Apr-17");
    chart.ChartData.SetValue(2, 5, 65);
    chart.ChartData.SetValue(3, 5, 25);
    chart.ChartData.SetValue(4, 5, 35);
    chart.ChartData.SetValue(1, 6, "5-Apr-17");
    chart.ChartData.SetValue(2, 6, 70);
    chart.ChartData.SetValue(3, 6, 30);
    chart.ChartData.SetValue(4, 6, 60);
    //Set region of Chart data.
    chart.DataRange = chart.ChartData[1, 1, 4, 6];
    //Set chart series in the column for assigned data region.
    chart.IsSeriesInRows = true;
    //Set chart type.
    chart.ChartType = OfficeChartType.Stock_HighLowClose;
    //Set a Chart Title.
    chart.ChartTitle = "High-Low-Close Chart";
    //Set primary category axis.
    chart.PrimaryCategoryAxis.NumberFormat = "dd-MMM-yy";
    //Set Datalabels.
    IOfficeChartSerie series1 = chart.Series[0];
    IOfficeChartSerie series2 = chart.Series[1];
    IOfficeChartSerie series3 = chart.Series[2];
 
    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.LineProperties.LinePattern = OfficeChartLinePattern.Solid;
    series3.SerieFormat.LineProperties.LineColor = Color.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 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 mergemerge 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.

See Also:

How to create line chart in Word document using C#?

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied