-
Notifications
You must be signed in to change notification settings - Fork 483
Expand file tree
/
Copy pathChartSample.cs
More file actions
226 lines (174 loc) · 6.97 KB
/
Copy pathChartSample.cs
File metadata and controls
226 lines (174 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/***************************************************************************************
Xceed Words for .NET – Xceed.Words.NET.Examples – Chart Sample Application
Copyright (c) 2009-2021 - Xceed Software Inc.
This application demonstrates how to create a chart when using the API
from the Xceed Words for .NET.
This file is part of Xceed Words for .NET. The source code in this file
is only intended as a supplement to the documentation, and is provided
"as is", without warranty of any kind, either expressed or implied.
*************************************************************************************/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using Xceed.Document.NET;
namespace Xceed.Words.NET.Examples
{
public class ChartSample
{
#region Private Members
private static string ChartSampleOutputDirectory = Program.SampleDirectory + @"Chart\Output\";
private static string ChartSampleResourceDirectory = Program.SampleDirectory + @"Chart\Resources\";
#endregion
#region Constructors
static ChartSample()
{
if( !Directory.Exists( ChartSample.ChartSampleOutputDirectory ) )
{
Directory.CreateDirectory( ChartSample.ChartSampleOutputDirectory );
}
}
#endregion
#region Public Methods
/// <summary>
/// Add a Bar chart to a document.
/// </summary>
public static void BarChart()
{
Console.WriteLine( "\tBarChart()" );
// Creates a document
using( var document = DocX.Create( ChartSample.ChartSampleOutputDirectory + @"BarChart.docx" ) )
{
// Add a title
document.InsertParagraph( "Bar Chart" ).FontSize( 15d ).SpacingAfter( 50d ).Alignment = Alignment.center;
// Create a bar chart.
var c = new BarChart();
c.AddLegend( ChartLegendPosition.Left, false );
c.BarDirection = BarDirection.Bar;
c.BarGrouping = BarGrouping.Standard;
c.GapWidth = 200;
// Create the data.
var canada = ChartData.CreateCanadaExpenses();
var usa = ChartData.CreateUSAExpenses();
var brazil = ChartData.CreateBrazilExpenses();
// Create and add series
var s1 = new Series( "Brazil" );
s1.Color = Color.GreenYellow;
s1.Bind( brazil, "Category", "Expenses" );
c.AddSeries( s1 );
var s2 = new Series( "USA" );
s2.Color = Color.LightBlue;
s2.Bind( usa, "Category", "Expenses" );
c.AddSeries( s2 );
var s3 = new Series( "Canada" );
s3.Color = Color.Gray;
s3.Bind( canada, "Category", "Expenses" );
c.AddSeries( s3 );
// Insert the chart into the document.
document.InsertParagraph( "Expenses(M$) for selected categories per country" ).FontSize( 15 ).SpacingAfter( 10d );
document.InsertChart( c, 350f, 550f );
document.Save();
Console.WriteLine( "\tCreated: BarChart.docx\n" );
}
}
/// <summary>
/// Add a Line chart to a document.
/// </summary>
public static void LineChart()
{
Console.WriteLine( "\tLineChart()" );
// Creates a document
using( var document = DocX.Create( ChartSample.ChartSampleOutputDirectory + @"LineChart.docx" ) )
{
// Add a title
document.InsertParagraph( "Line Chart" ).FontSize( 15d ).SpacingAfter( 50d ).Alignment = Alignment.center;
// Create a line chart.
var c = new LineChart();
c.AddLegend( ChartLegendPosition.Left, false );
// Create the data.
var canada = ChartData.CreateCanadaExpenses();
var usa = ChartData.CreateUSAExpenses();
var brazil = ChartData.CreateBrazilExpenses();
// Create and add series
var s1 = new Series( "Brazil" );
s1.Color = Color.Yellow;
s1.Bind( brazil, "Category", "Expenses" );
c.AddSeries( s1 );
var s2 = new Series( "USA" );
s2.Color = Color.Blue;
s2.Bind( usa, "Category", "Expenses" );
c.AddSeries( s2 );
var s3 = new Series( "Canada" );
s3.Color = Color.Red;
s3.Bind( canada, "Category", "Expenses" );
c.AddSeries( s3 );
// Insert chart into document
document.InsertParagraph( "Expenses(M$) for selected categories per country" ).FontSize( 15 ).SpacingAfter( 10d );
document.InsertChart( c );
document.Save();
Console.WriteLine( "\tCreated: LineChart.docx\n" );
}
}
/// <summary>
/// Add a Pie chart to a document.
/// </summary>
public static void PieChart()
{
Console.WriteLine( "\tPieChart()" );
// Creates a document
using( var document = DocX.Create( ChartSample.ChartSampleOutputDirectory + @"PieChart.docx" ) )
{
// Add a title
document.InsertParagraph( "Pie Chart" ).FontSize( 15d ).SpacingAfter( 50d ).Alignment = Alignment.center;
// Create a pie chart.
var c = new PieChart();
c.AddLegend( ChartLegendPosition.Left, false );
// Create the data.
var brazil = ChartData.CreateBrazilExpenses();
// Create and add series
var s1 = new Series( "Brazil" );
s1.Bind( brazil, "Category", "Expenses" );
c.AddSeries( s1 );
// Insert chart into document
document.InsertParagraph( "Expenses(M$) for selected categories in Brazil" ).FontSize( 15 ).SpacingAfter( 10d );
document.InsertChart( c );
document.Save();
Console.WriteLine( "\tCreated: PieChart.docx\n" );
}
}
/// <summary>
/// Add a 3D bar chart to a document.
/// </summary>
///
public static void Chart3D()
{
Console.WriteLine( "\tChart3D()" );
// Creates a document
using( var document = DocX.Create( ChartSample.ChartSampleOutputDirectory + @"3DChart.docx" ) )
{
// Add a title
document.InsertParagraph( "3D Chart" ).FontSize( 15d ).SpacingAfter( 50d ).Alignment = Alignment.center;
// Create a 3D Bar chart.
var c = new BarChart();
c.View3D = true;
// Create the data.
var brazil = ChartData.CreateBrazilExpenses();
// Create and add series
var s1 = new Series( "Brazil" );
s1.Color = Color.GreenYellow;
s1.Bind( brazil, "Category", "Expenses" );
c.AddSeries( s1 );
// Insert chart into document
document.InsertParagraph( "Expenses(M$) for selected categories in Brazil" ).FontSize( 15 ).SpacingAfter( 10d );
document.InsertChart( c );
document.Save();
Console.WriteLine( "\tCreated: 3DChart.docx\n" );
}
}
public static void ModifyChartData()
{
// This option is available when you buy Xceed Words for .NET from https://xceed.com/xceed-words-for-net/.
}
#endregion
}
}