Skip to content

Commit

Permalink
Updated API examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vderyushev committed Jun 4, 2024
1 parent c53f31e commit d2d83d2
Show file tree
Hide file tree
Showing 12 changed files with 798 additions and 432 deletions.
279 changes: 279 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExCharts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;

namespace ApiExamples
Expand Down Expand Up @@ -1877,5 +1878,283 @@ public void RemoveSecondaryAxis()
seriesGroups.RemoveAt(i);
//ExEnd:RemoveSecondaryAxis
}

[Test]
public void TreemapChart()
{
//ExStart:TreemapChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, ChartMultilevelValue[], double[])
//ExFor:ChartMultilevelValue(String, String)
//ExSummary:Shows how to create treemap chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Treemap chart.
Shape shape = builder.InsertChart(ChartType.Treemap, 450, 280);
Chart chart = shape.Chart;
chart.Title.Text = "World Population";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
ChartSeries series = chart.Series.Add(
"Population by Region",
new ChartMultilevelValue[]
{
new ChartMultilevelValue("Asia", "China"),
new ChartMultilevelValue("Asia", "India"),
new ChartMultilevelValue("Asia", "Indonesia"),
new ChartMultilevelValue("Asia", "Pakistan"),
new ChartMultilevelValue("Asia", "Bangladesh"),
new ChartMultilevelValue("Asia", "Japan"),
new ChartMultilevelValue("Asia", "Philippines"),
new ChartMultilevelValue("Asia", "Other"),
new ChartMultilevelValue("Africa", "Nigeria"),
new ChartMultilevelValue("Africa", "Ethiopia"),
new ChartMultilevelValue("Africa", "Egypt"),
new ChartMultilevelValue("Africa", "Other"),
new ChartMultilevelValue("Europe", "Russia"),
new ChartMultilevelValue("Europe", "Germany"),
new ChartMultilevelValue("Europe", "Other"),
new ChartMultilevelValue("Latin America", "Brazil"),
new ChartMultilevelValue("Latin America", "Mexico"),
new ChartMultilevelValue("Latin America", "Other"),
new ChartMultilevelValue("Northern America", "United States"),
new ChartMultilevelValue("Northern America", "Other"),
new ChartMultilevelValue("Oceania")
},
new double[]
{
1409670000, 1400744000, 279118866, 241499431, 169828911, 123930000, 112892781, 764000000,
223800000, 107334000, 105914499, 903000000,
146150789, 84607016, 516000000,
203080756, 129713690, 310000000,
335893238, 35000000,
42000000
});

// Show data labels.
series.HasDataLabels = true;
series.DataLabels.ShowValue = true;
series.DataLabels.ShowCategoryName = true;
string thousandSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyGroupSeparator;
series.DataLabels.NumberFormat.FormatCode = $"#{thousandSeparator}0";

doc.Save(ArtifactsDir + "Charts.Treemap.docx");
//ExEnd:TreemapChart
}

[Test]
public void SunburstChart()
{
//ExStart:SunburstChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, ChartMultilevelValue[], double[])
//ExSummary:Shows how to create sunburst chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Sunburst chart.
Shape shape = builder.InsertChart(ChartType.Sunburst, 450, 450);
Chart chart = shape.Chart;
chart.Title.Text = "Sales";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
ChartSeries series = chart.Series.Add(
"Sales",
new ChartMultilevelValue[]
{
new ChartMultilevelValue("Sales - Europe", "UK", "London Dep."),
new ChartMultilevelValue("Sales - Europe", "UK", "Liverpool Dep."),
new ChartMultilevelValue("Sales - Europe", "UK", "Manchester Dep."),
new ChartMultilevelValue("Sales - Europe", "France", "Paris Dep."),
new ChartMultilevelValue("Sales - Europe", "France", "Lyon Dep."),
new ChartMultilevelValue("Sales - NA", "USA", "Denver Dep."),
new ChartMultilevelValue("Sales - NA", "USA", "Seattle Dep."),
new ChartMultilevelValue("Sales - NA", "USA", "Detroit Dep."),
new ChartMultilevelValue("Sales - NA", "USA", "Houston Dep."),
new ChartMultilevelValue("Sales - NA", "Canada", "Toronto Dep."),
new ChartMultilevelValue("Sales - NA", "Canada", "Montreal Dep."),
new ChartMultilevelValue("Sales - Oceania", "Australia", "Sydney Dep."),
new ChartMultilevelValue("Sales - Oceania", "New Zealand", "Auckland Dep.")
},
new double[] { 1236, 851, 536, 468, 179, 527, 799, 1148, 921, 457, 482, 761, 694 });

// Show data labels.
series.HasDataLabels = true;
series.DataLabels.ShowValue = false;
series.DataLabels.ShowCategoryName = true;

doc.Save(ArtifactsDir + "Charts.Sunburst.docx");
//ExEnd:SunburstChart
}

public void HistogramChart()
{
//ExStart:HistogramChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, double[])
//ExSummary:Shows how to create histogram chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Histogram chart.
Shape shape = builder.InsertChart(ChartType.Histogram, 450, 450);
Chart chart = shape.Chart;
chart.Title.Text = "Avg Temperature since 1991";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
chart.Series.Add(
"Avg Temperature",
new double[]
{
51.8, 53.6, 50.3, 54.7, 53.9, 54.3, 53.4, 52.9, 53.3, 53.7, 53.8, 52.0, 55.0, 52.1, 53.4,
53.8, 53.8, 51.9, 52.1, 52.7, 51.8, 56.6, 53.3, 55.6, 56.3, 56.2, 56.1, 56.2, 53.6, 55.7,
56.3, 55.9, 55.6
});

doc.Save(ArtifactsDir + "Charts.Histogram.docx");
//ExEnd:HistogramChart
}

public void ParetoChart()
{
//ExStart:ParetoChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, String[], double[])
//ExSummary:Shows how to create pareto chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Pareto chart.
Shape shape = builder.InsertChart(ChartType.Pareto, 450, 450);
Chart chart = shape.Chart;
chart.Title.Text = "Best-Selling Car";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
chart.Series.Add(
"Best-Selling Car",
new string[] { "Tesla Model Y", "Toyota Corolla", "Toyota RAV4", "Ford F-Series", "Honda CR-V" },
new double[] { 1.43, 0.91, 1.17, 0.98, 0.85 });

doc.Save(ArtifactsDir + "Charts.Pareto.docx");
//ExEnd:ParetoChart
}

public void BoxAndWhiskerChart()
{
//ExStart:BoxAndWhiskerChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, String[], double[])
//ExSummary:Shows how to create box and whisker chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Box & Whisker chart.
Shape shape = builder.InsertChart(ChartType.BoxAndWhisker, 450, 450);
Chart chart = shape.Chart;
chart.Title.Text = "Points by Years";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
ChartSeries series = chart.Series.Add(
"Points by Years",
new string[]
{
"WC", "WC", "WC", "WC", "WC", "WC", "WC", "WC", "WC", "WC",
"NR", "NR", "NR", "NR", "NR", "NR", "NR", "NR", "NR", "NR",
"NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA", "NA"
},
new double[]
{
91, 80, 100, 77, 90, 104, 105, 118, 120, 101,
114, 107, 110, 60, 79, 78, 77, 102, 101, 113,
94, 93, 84, 71, 80, 103, 80, 94, 100, 101
});

// Show data labels.
series.HasDataLabels = true;

doc.Save(ArtifactsDir + "Charts.BoxAndWhisker.docx");
//ExEnd:BoxAndWhiskerChart
}

[Test]
public void WaterfallChart()
{
//ExStart:WaterfallChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, String[], double[], bool[])
//ExSummary:Shows how to create waterfall chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Waterfall chart.
Shape shape = builder.InsertChart(ChartType.Waterfall, 450, 450);
Chart chart = shape.Chart;
chart.Title.Text = "New Zealand GDP";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
ChartSeries series = chart.Series.Add(
"New Zealand GDP",
new string[] { "2018", "2019 growth", "2020 growth", "2020", "2021 growth", "2022 growth", "2022" },
new double[] { 100, 0.57, -0.25, 100.32, 20.22, -2.92, 117.62 },
new bool[] { true, false, false, true, false, false, true });

// Show data labels.
series.HasDataLabels = true;

doc.Save(ArtifactsDir + "Charts.Waterfall.docx");
//ExEnd:WaterfallChart
}

[Test]
public void FunnelChart()
{
//ExStart:FunnelChart
//ReleaseVersion:24.6
//ExFor:ChartSeriesCollection.Add(String, String[], double[])
//ExSummary:Shows how to create funnel chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a Funnel chart.
Shape shape = builder.InsertChart(ChartType.Funnel, 450, 450);
Chart chart = shape.Chart;
chart.Title.Text = "Population by Age Group";

// Delete default generated series.
chart.Series.Clear();

// Add a series.
ChartSeries series = chart.Series.Add(
"Population by Age Group",
new string[] { "0-9", "10-19", "20-29", "30-39", "40-49", "50-59", "60-69", "70-79", "80-89", "90-" },
new double[] { 0.121, 0.128, 0.132, 0.146, 0.124, 0.124, 0.111, 0.075, 0.032, 0.007 });

// Show data labels.
series.HasDataLabels = true;
string decimalSeparator = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
series.DataLabels.NumberFormat.FormatCode = $"0{decimalSeparator}0%";

doc.Save(ArtifactsDir + "Charts.Funnel.docx");
//ExEnd:FunnelChart
}
}
}
25 changes: 25 additions & 0 deletions Examples/ApiExamples/ApiExamples/ExComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,30 @@ private void IndentAndAppendLine(string text)
private readonly StringBuilder mBuilder;
}
//ExEnd

[Test]
public void UtcDateTime()
{
//ExStart:UtcDateTime
//ReleaseVersion:24.6
//ExFor:Comment.DateTimeUtc
//ExSummary:Shows how to get UTC date and time.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

DateTime dateTime = DateTime.Now;
Comment comment = new Comment(doc, "John Doe", "J.D.", dateTime);
comment.SetText("My comment.");

builder.CurrentParagraph.AppendChild(comment);

doc.Save(ArtifactsDir + "Comment.UtcDateTime.docx");
doc = new Document(ArtifactsDir + "Comment.UtcDateTime.docx");

comment = (Comment)doc.GetChild(NodeType.Comment, 0, true);
// By default DateTimeUtc without millisaconds.
Assert.AreEqual(dateTime.ToUniversalTime().ToString("yyyy-MM-dd hh:mm:ss"), comment.DateTimeUtc.ToString("yyyy-MM-dd hh:mm:ss"));
//ExEnd:UtcDateTime
}
}
}
Loading

0 comments on commit d2d83d2

Please sign in to comment.