1+ using Syncfusion . XlsIO ;
2+ using System ;
3+
4+ namespace GaugeChart
5+ {
6+ class Program
7+ {
8+ public static void Main ( string [ ] args )
9+ {
10+ using ( ExcelEngine excelEngine = new ExcelEngine ( ) )
11+ {
12+ IApplication application = excelEngine . Excel ;
13+ application . DefaultVersion = ExcelVersion . Xlsx ;
14+ IWorkbook workbook = application . Workbooks . Create ( 1 ) ;
15+ IWorksheet sheet = workbook . Worksheets [ 0 ] ;
16+
17+ //Adding values in worksheet
18+ sheet . Range [ "A1" ] . Value = "Value" ;
19+ sheet . Range [ "A2" ] . Value = "30" ;
20+ sheet . Range [ "A3" ] . Value = "60" ;
21+ sheet . Range [ "A4" ] . Value = "90" ;
22+ sheet . Range [ "A5" ] . Value = "180" ;
23+ sheet . Range [ "C2" ] . Value = "value" ;
24+ sheet . Range [ "C3" ] . Value = "pointer" ;
25+ sheet . Range [ "C4" ] . Value = "End" ;
26+ sheet . Range [ "D2" ] . Value = "10" ;
27+ sheet . Range [ "D3" ] . Value = "1" ;
28+ sheet . Range [ "D4" ] . Value = "189" ;
29+
30+ //Adding doughnut chart in worksheet
31+ IChartShape chart = sheet . Charts . Add ( ) ;
32+ chart . ChartType = ExcelChartType . Doughnut ;
33+ chart . DataRange = sheet . Range [ "A1:A5" ] ;
34+ chart . IsSeriesInRows = false ;
35+
36+ //Formatting value series
37+ chart . Series [ "Value" ] . SerieFormat . CommonSerieOptions . DoughnutHoleSize = 60 ;
38+ chart . Series [ "Value" ] . SerieFormat . CommonSerieOptions . FirstSliceAngle = 270 ;
39+ chart . Series [ "Value" ] . DataPoints [ 3 ] . DataFormat . Fill . Visible = false ;
40+
41+ //Adding pointer series as Pie chart
42+ chart . Series . Add ( "Pointer" ) ;
43+ chart . Series [ "Pointer" ] . SerieType = ExcelChartType . Pie ;
44+ chart . Series [ "Pointer" ] . Values = sheet . Range [ "D2:D4" ] ;
45+ chart . Series [ "Pointer" ] . UsePrimaryAxis = false ;
46+
47+ //Formatting pointer series
48+ chart . Series [ "Pointer" ] . SerieFormat . CommonSerieOptions . FirstSliceAngle = 270 ;
49+ chart . Series [ "Pointer" ] . DataPoints [ 0 ] . DataFormat . Fill . Visible = false ;
50+ chart . Series [ "Pointer" ] . DataPoints [ 1 ] . DataFormat . Fill . ForeColorIndex = ExcelKnownColors . Black ;
51+ chart . Series [ "Pointer" ] . DataPoints [ 2 ] . DataFormat . Fill . Visible = false ;
52+
53+ //Saving the workbook as stream
54+ FileStream outputStream = new FileStream ( Path . GetFullPath ( "Output/Output.xlsx" ) , FileMode . Create , FileAccess . Write ) ;
55+ workbook . SaveAs ( outputStream ) ;
56+ }
57+ }
58+ }
59+ }
0 commit comments