1+ using Syncfusion . DocIO . DLS ;
2+ using Syncfusion . Drawing ;
3+ using Syncfusion . OfficeChart ;
4+
5+ using ( WordDocument document = new WordDocument ( ) )
6+ {
7+ // Add a section
8+ IWSection section = document . AddSection ( ) ;
9+
10+ // Add spacing before inserting chart
11+ section . AddParagraph ( ) ;
12+
13+ // Add chart to the section
14+ IWParagraph chartParagraph = section . AddParagraph ( ) ;
15+ WChart chart = chartParagraph . AppendChart ( 500 , 300 ) ;
16+
17+ // Set chart type to Stacked Bar
18+ chart . ChartType = OfficeChartType . Bar_Stacked ;
19+
20+ // Chart data
21+ chart . ChartData . SetValue ( 1 , 1 , "Task" ) ;
22+ chart . ChartData . SetValue ( 1 , 2 , "Start" ) ;
23+ chart . ChartData . SetValue ( 1 , 3 , "Duration" ) ;
24+
25+ chart . ChartData . SetValue ( 2 , 1 , "Planning" ) ;
26+ chart . ChartData . SetValue ( 2 , 2 , 0 ) ;
27+ chart . ChartData . SetValue ( 2 , 3 , 5 ) ;
28+
29+ chart . ChartData . SetValue ( 3 , 1 , "Design" ) ;
30+ chart . ChartData . SetValue ( 3 , 2 , 5 ) ;
31+ chart . ChartData . SetValue ( 3 , 3 , 7 ) ;
32+
33+ chart . ChartData . SetValue ( 4 , 1 , "Testing" ) ;
34+ chart . ChartData . SetValue ( 4 , 2 , 12 ) ;
35+ chart . ChartData . SetValue ( 4 , 3 , 4 ) ;
36+
37+ chart . ChartData . SetValue ( 5 , 1 , "Deployment" ) ;
38+ chart . ChartData . SetValue ( 5 , 2 , 16 ) ;
39+ chart . ChartData . SetValue ( 5 , 3 , 3 ) ;
40+
41+ chart . ChartData . SetValue ( 6 , 1 , "Support" ) ;
42+ chart . ChartData . SetValue ( 6 , 2 , 19 ) ;
43+ chart . ChartData . SetValue ( 6 , 3 , 1 ) ;
44+
45+ // Set data range
46+ chart . DataRange = chart . ChartData [ 1 , 1 , 6 , 3 ] ;
47+
48+ // First series = Start (hide transparent)
49+ IOfficeChartSerie startSeries = chart . Series [ 0 ] ;
50+ startSeries . SerieFormat . Fill . FillType = OfficeFillType . SolidColor ;
51+ startSeries . SerieFormat . Fill . ForeColor = Color . Transparent ;
52+
53+ // Second series = Duration
54+ IOfficeChartSerie durationSeries = chart . Series [ 1 ] ;
55+ durationSeries . SerieFormat . Fill . ForeColor = Color . FromArgb ( 141 , 201 , 219 ) ;
56+
57+ // Reverse task order (top to bottom)
58+ chart . PrimaryCategoryAxis . ReversePlotOrder = true ;
59+
60+ // Show vertical gridlines
61+ chart . PrimaryValueAxis . HasMajorGridLines = true ;
62+
63+ // Remove legend
64+ chart . HasLegend = false ;
65+
66+ // Gap width similar to Gantt chart
67+ durationSeries . SerieFormat . CommonSerieOptions . GapWidth = 30 ;
68+
69+ // Chart area background
70+ chart . ChartArea . Fill . ForeColor = Color . Transparent ;
71+
72+ // Axis min/max
73+ chart . PrimaryValueAxis . MinimumValue = 0 ;
74+ chart . PrimaryValueAxis . MaximumValue = 20 ;
75+ chart . PrimaryValueAxis . MajorUnit = 2 ;
76+
77+ // Set chart title
78+ chart . ChartTitle = "Gantt Chart" ;
79+
80+ // Hide major gridlines on value axis
81+ chart . PrimaryValueAxis . HasMajorGridLines = false ;
82+
83+ // Save document
84+ document . Save ( @"../../../Output/GanttChart.docx" ) ;
85+ }
0 commit comments