1+ using Syncfusion . DocIO ;
2+ using Syncfusion . DocIO . DLS ;
3+ using Syncfusion . OfficeChart ;
4+ using System . IO ;
5+
6+
7+ //Loads the template document.
8+ WordDocument document = new WordDocument ( ) ;
9+ // Adds section to the document.
10+ IWSection sec = document . AddSection ( ) ;
11+ //Adds paragraph to the section.
12+ IWParagraph paragraph = sec . AddParagraph ( ) ;
13+ //Creates and Appends chart to the paragraph.
14+ WChart chart = paragraph . AppendChart ( 446 , 270 ) ;
15+ chart . ChartType = OfficeChartType . Column_Clustered ;
16+ //Assign data
17+ AddChartData ( chart ) ;
18+ chart . IsSeriesInRows = false ;
19+ //Apply chart elements
20+ //Set chart title
21+ chart . ChartTitle = "Sales Report in Clustered Column Chart" ;
22+ //Set Datalabels
23+ IOfficeChartSerie serie1 = chart . Series . Add ( "Amount(in $)" ) ;
24+ //Sets the data range of chart series – start row, start column, end row, end column
25+ serie1 . Values = chart . ChartData [ 2 , 2 , 6 , 2 ] ;
26+ IOfficeChartSerie serie2 = chart . Series . Add ( "Count" ) ;
27+ //Sets the data range of chart series start row, start column, end row, end column
28+ serie2 . Values = chart . ChartData [ 2 , 3 , 6 , 3 ] ;
29+ //Sets the data range of the category axis
30+ chart . PrimaryCategoryAxis . CategoryLabels = chart . ChartData [ 2 , 1 , 6 , 1 ] ;
31+ serie1 . DataPoints . DefaultDataPoint . DataLabels . IsValue = true ;
32+ serie2 . DataPoints . DefaultDataPoint . DataLabels . IsValue = true ;
33+ serie1 . DataPoints . DefaultDataPoint . DataLabels . Position = OfficeDataLabelPosition . Outside ;
34+ serie2 . DataPoints . DefaultDataPoint . DataLabels . Position = OfficeDataLabelPosition . Outside ;
35+ //Set legend
36+ chart . HasLegend = true ;
37+ chart . Legend . Position = OfficeLegendPosition . Bottom ;
38+ //Save the Word document
39+ document . Save ( Path . GetFullPath ( @"Output/Output.docx" ) ) ;
40+
41+
42+ /// <summary>
43+ /// Set the values for the chart
44+ /// </summary>
45+ /// <param name="chart">Represent the instance of the chart</param>
46+
47+ static void AddChartData ( WChart chart )
48+ {
49+ //Set the value for chart data
50+ chart . ChartData . SetValue ( 1 , 1 , "Items" ) ;
51+ chart . ChartData . SetValue ( 1 , 2 , "Amount(in $)" ) ;
52+ chart . ChartData . SetValue ( 1 , 3 , "Count" ) ;
53+
54+ chart . ChartData . SetValue ( 2 , 1 , "Beverages" ) ;
55+ chart . ChartData . SetValue ( 2 , 2 , 2776 ) ;
56+ chart . ChartData . SetValue ( 2 , 3 , 925 ) ;
57+
58+ chart . ChartData . SetValue ( 3 , 1 , "Condiments" ) ;
59+ chart . ChartData . SetValue ( 3 , 2 , 1077 ) ;
60+ chart . ChartData . SetValue ( 3 , 3 , 378 ) ;
61+
62+ chart . ChartData . SetValue ( 4 , 1 , "Confections" ) ;
63+ chart . ChartData . SetValue ( 4 , 2 , 2287 ) ;
64+ chart . ChartData . SetValue ( 4 , 3 , 880 ) ;
65+
66+ chart . ChartData . SetValue ( 5 , 1 , "Dairy Products" ) ;
67+ chart . ChartData . SetValue ( 5 , 2 , 1368 ) ;
68+ chart . ChartData . SetValue ( 5 , 3 , 581 ) ;
69+
70+ chart . ChartData . SetValue ( 6 , 1 , "Grains/Cereals" ) ;
71+ chart . ChartData . SetValue ( 6 , 2 , 3325 ) ;
72+ chart . ChartData . SetValue ( 6 , 3 , 189 ) ;
73+ }
0 commit comments