|
5 | 5 | { |
6 | 6 | // Adds a section to the document. |
7 | 7 | IWSection sec = document.AddSection(); |
8 | | - |
9 | 8 | // Adds a paragraph to the section. |
10 | 9 | IWParagraph paragraph = sec.AddParagraph(); |
11 | | - |
12 | 10 | // Loads the Excel file as a stream. |
13 | 11 | Stream excelStream = File.OpenRead(Path.GetFullPath("Data/InputTemplate.xlsx")); |
14 | | - |
15 | 12 | // Creates and appends a chart to the paragraph with the Excel stream as a parameter. |
16 | 13 | // The chart is created based on the data from the Excel file (range A1:D6), with specified width and height. |
17 | 14 | WChart chart = paragraph.AppendChart(excelStream, 1, "A1:D6", 470, 300); |
18 | | - |
19 | 15 | // Sets the chart type to Stacked Bar Chart. |
20 | 16 | chart.ChartType = Syncfusion.OfficeChart.OfficeChartType.Bar_Stacked; |
21 | | - |
22 | 17 | // Apply chart elements. |
23 | 18 | // Sets the chart title. |
24 | 19 | chart.ChartTitle = "Stacked Bar Chart"; |
25 | | - |
26 | 20 | // Displays data labels for the third series (Series 2). |
27 | 21 | chart.Series[2].DataPoints.DefaultDataPoint.DataLabels.IsValue = true; |
28 | 22 |
|
29 | 23 | // Manually positions the data labels for each data point in the third series. |
30 | 24 | chart.Series[2].DataPoints[0].DataLabels.Text = "Label 1"; |
31 | 25 | chart.Series[2].DataPoints[0].DataLabels.Layout.ManualLayout.Left = 0.1; |
32 | | - |
33 | 26 | chart.Series[2].DataPoints[1].DataLabels.Text = "Label 2"; |
34 | 27 | chart.Series[2].DataPoints[1].DataLabels.Layout.ManualLayout.Left = 0.1; |
35 | | - |
36 | 28 | chart.Series[2].DataPoints[2].DataLabels.Text = "Label 3"; |
37 | 29 | chart.Series[2].DataPoints[2].DataLabels.Layout.ManualLayout.Left = 0.13; |
38 | | - |
39 | 30 | chart.Series[2].DataPoints[3].DataLabels.Text = "Label 4"; |
40 | 31 | chart.Series[2].DataPoints[3].DataLabels.Layout.ManualLayout.Left = 0.18; |
41 | | - |
42 | 32 | chart.Series[2].DataPoints[4].DataLabels.Text = "Label 5"; |
43 | 33 | chart.Series[2].DataPoints[4].DataLabels.Layout.ManualLayout.Left = 0.20; |
44 | 34 |
|
45 | 35 | // Sets the chart legend and positions it at the bottom of the chart. |
46 | 36 | chart.HasLegend = true; |
47 | 37 | chart.Legend.Position = Syncfusion.OfficeChart.OfficeLegendPosition.Bottom; |
48 | | - |
49 | 38 | using (FileStream outputStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write)) |
50 | 39 | { |
51 | 40 | // Saves the generated Word document to the specified file stream in DOCX format. |
|
0 commit comments