Skip to content

Commit 72cd24a

Browse files
committed
Added the code for sunburst
1 parent f15ccaa commit 72cd24a

File tree

1 file changed

+54
-1
lines changed
  • Charts/Create-sunburst-chart/.NET/Create-sunburst-chart

1 file changed

+54
-1
lines changed

Charts/Create-sunburst-chart/.NET/Create-sunburst-chart/Program.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,60 @@ static void Main(string[] args)
1212
//Create a new Word document.
1313
using (WordDocument document = new WordDocument())
1414
{
15-
15+
// Add a section & a paragraph to the document.
16+
IWSection section = document.AddSection();
17+
IWParagraph paragraph = section.AddParagraph();
18+
19+
// Create and append Sunburst chart to the paragraph.
20+
WChart chart = paragraph.AppendChart(446, 270);
21+
chart.ChartType = OfficeChartType.SunBurst;
22+
23+
// Set chart title.
24+
chart.ChartTitle = "Sales by Annual - Sunburst Chart";
25+
26+
// Set headers.
27+
chart.ChartData.SetValue(1, 1, "Quarter");
28+
chart.ChartData.SetValue(1, 2, "Month");
29+
chart.ChartData.SetValue(1, 3, "Week");
30+
chart.ChartData.SetValue(1, 4, "Sales");
31+
32+
// Add data rows.
33+
string[,] data = {
34+
{"1st", "Jan", "", "3.5"},
35+
{"1st", "Feb", "Week 1", "1.2"},
36+
{"1st", "Feb", "Week 2", "0.8"},
37+
{"1st", "Feb", "Week 3", "0.6"},
38+
{"1st", "Feb", "Week 4", "0.5"},
39+
{"1st", "Mar", "", "1.7"},
40+
{"2nd", "Apr", "", "1.1"},
41+
{"2nd", "May", "", "0.8"},
42+
{"2nd", "Jun", "", "0.8"},
43+
{"3rd", "Jul", "", "1"},
44+
{"3rd", "Aug", "", "0.7"},
45+
{"3rd", "Sep", "", "0.9"},
46+
{"4th", "Oct", "", "2"},
47+
{"4th", "Nov", "", "2"},
48+
{"4th", "Dec", "", "2"}
49+
};
50+
51+
for (int i = 0; i < data.GetLength(0); i++)
52+
{
53+
chart.ChartData.SetValue(i + 2, 1, data[i, 0]);
54+
chart.ChartData.SetValue(i + 2, 2, data[i, 1]);
55+
chart.ChartData.SetValue(i + 2, 3, data[i, 2]);
56+
chart.ChartData.SetValue(i + 2, 4, float.Parse(data[i, 3]));
57+
}
58+
59+
// Set data range and hierarchy.
60+
chart.DataRange = chart.ChartData[2, 1, data.GetLength(0) + 1, 4];
61+
// Set DataLabels.
62+
IOfficeChartSerie serie = chart.Series[0];
63+
serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
64+
65+
// Set legend.
66+
chart.HasLegend = true;
67+
chart.Legend.Position = OfficeLegendPosition.Bottom;
68+
1669
//Create a file stream.
1770
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite))
1871
{

0 commit comments

Comments
 (0)