Skip to content

Commit 6bfa579

Browse files
removed the namespace in Program.cs
1 parent c6f1ac3 commit 6bfa579

1 file changed

Lines changed: 64 additions & 72 deletions

File tree

  • Charts/Create-clustered-column-chart/.NET/Create-clustered-column-chart

Charts/Create-clustered-column-chart/.NET/Create-clustered-column-chart/Program.cs

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,76 @@
33
using Syncfusion.OfficeChart;
44
using System.IO;
55

6-
namespace Create_clustered_column_chart
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+
//Create a file stream.
39+
//Create a file stream.
40+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite))
741
{
8-
class Program
9-
{
10-
static void Main(string[] args)
11-
{
12-
//Loads the template document.
13-
WordDocument document = new WordDocument();
14-
// Adds section to the document.
15-
IWSection sec = document.AddSection();
16-
//Adds paragraph to the section.
17-
IWParagraph paragraph = sec.AddParagraph();
18-
//Creates and Appends chart to the paragraph.
19-
WChart chart = paragraph.AppendChart(446, 270);
20-
chart.ChartType = OfficeChartType.Column_Clustered;
42+
//Save the Word document to the file stream.
43+
document.Save(outputFileStream, FormatType.Docx);
44+
}
2145

22-
//Assign data
23-
AddChartData(chart);
24-
chart.IsSeriesInRows = false;
25-
//Apply chart elements
26-
//Set chart title
27-
chart.ChartTitle = "Sales Report in Clustered Column Chart";
28-
//Set Datalabels
29-
IOfficeChartSerie serie1 = chart.Series.Add("Amount(in $)");
30-
//Sets the data range of chart series – start row, start column, end row, end column
31-
serie1.Values = chart.ChartData[2, 2, 6, 2];
32-
IOfficeChartSerie serie2 = chart.Series.Add("Count");
33-
//Sets the data range of chart series start row, start column, end row, end column
34-
serie2.Values = chart.ChartData[2, 3, 6, 3];
35-
//Sets the data range of the category axis
36-
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 6, 1];
37-
serie1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
38-
serie2.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
39-
serie1.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside;
40-
serie2.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside;
41-
//Set legend
42-
chart.HasLegend = true;
43-
chart.Legend.Position = OfficeLegendPosition.Bottom;
44-
//Create a file stream.
45-
//Create a file stream.
46-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.ReadWrite))
47-
{
48-
//Save the Word document to the file stream.
49-
document.Save(outputFileStream, FormatType.Docx);
50-
}
5146

52-
}
53-
/// <summary>
54-
/// Set the values for the chart
55-
/// </summary>
56-
/// <param name="chart">Represent the instance of the chart</param>
47+
/// <summary>
48+
/// Set the values for the chart
49+
/// </summary>
50+
/// <param name="chart">Represent the instance of the chart</param>
5751

58-
private static void AddChartData(WChart chart)
59-
{
60-
//Set the value for chart data
61-
chart.ChartData.SetValue(1, 1, "Items");
62-
chart.ChartData.SetValue(1, 2, "Amount(in $)");
63-
chart.ChartData.SetValue(1, 3, "Count");
52+
static void AddChartData(WChart chart)
53+
{
54+
//Set the value for chart data
55+
chart.ChartData.SetValue(1, 1, "Items");
56+
chart.ChartData.SetValue(1, 2, "Amount(in $)");
57+
chart.ChartData.SetValue(1, 3, "Count");
6458

65-
chart.ChartData.SetValue(2, 1, "Beverages");
66-
chart.ChartData.SetValue(2, 2, 2776);
67-
chart.ChartData.SetValue(2, 3, 925);
59+
chart.ChartData.SetValue(2, 1, "Beverages");
60+
chart.ChartData.SetValue(2, 2, 2776);
61+
chart.ChartData.SetValue(2, 3, 925);
6862

69-
chart.ChartData.SetValue(3, 1, "Condiments");
70-
chart.ChartData.SetValue(3, 2, 1077);
71-
chart.ChartData.SetValue(3, 3, 378);
63+
chart.ChartData.SetValue(3, 1, "Condiments");
64+
chart.ChartData.SetValue(3, 2, 1077);
65+
chart.ChartData.SetValue(3, 3, 378);
7266

73-
chart.ChartData.SetValue(4, 1, "Confections");
74-
chart.ChartData.SetValue(4, 2, 2287);
75-
chart.ChartData.SetValue(4, 3, 880);
67+
chart.ChartData.SetValue(4, 1, "Confections");
68+
chart.ChartData.SetValue(4, 2, 2287);
69+
chart.ChartData.SetValue(4, 3, 880);
7670

77-
chart.ChartData.SetValue(5, 1, "Dairy Products");
78-
chart.ChartData.SetValue(5, 2, 1368);
79-
chart.ChartData.SetValue(5, 3, 581);
71+
chart.ChartData.SetValue(5, 1, "Dairy Products");
72+
chart.ChartData.SetValue(5, 2, 1368);
73+
chart.ChartData.SetValue(5, 3, 581);
8074

81-
chart.ChartData.SetValue(6, 1, "Grains/Cereals");
82-
chart.ChartData.SetValue(6, 2, 3325);
83-
chart.ChartData.SetValue(6, 3, 189);
84-
}
85-
}
86-
}
75+
chart.ChartData.SetValue(6, 1, "Grains/Cereals");
76+
chart.ChartData.SetValue(6, 2, 3325);
77+
chart.ChartData.SetValue(6, 3, 189);
78+
}

0 commit comments

Comments
 (0)