Tutorial: How to Work with Charts in GroupDocs.Assembly Cloud
Overview
In this tutorial, you’ll learn how to work with charts in GroupDocs.Assembly Cloud, creating dynamic document templates that can generate various types of data visualizations. Charts are powerful tools for presenting data in a visual format that makes trends and patterns immediately apparent.
Learning Objectives
By the end of this tutorial, you will be able to:
- Bind charts to dynamic data sources
- Configure different chart types (line, column, bar, pie, etc.)
- Customize chart appearance with dynamic titles and labels
- Set dynamic chart colors based on data values
- Apply filtering to chart series
- Create advanced multi-series charts
Prerequisites
Before starting this tutorial, you should have:
- A GroupDocs.Assembly Cloud account (sign up for a free trial)
- Basic understanding of template syntax and data processing
- Familiarity with chart types and their appropriate use cases
- Your development environment set up (any language with the GroupDocs.Assembly Cloud SDK installed)
Understanding Chart Components in Templates
Charts in document templates contain several components that can be customized:
- Chart Title - The main heading of the chart
- Series - Data sets represented in the chart
- Data Points - Individual values within a series
- Axes - The horizontal and vertical reference lines
- Legend - The key explaining what each series represents
GroupDocs.Assembly Cloud provides special tags to bind these components to your data source.
Binding a Chart to a Data Source
The fundamental step in chart generation is binding it to your data source using chart series tags.
Basic Chart Setup Process
- Add a chart to your template at the desired location
- Configure the chart’s appearance (type, style, size)
- Add required chart series and configure their appearance
- Add a title to the chart if needed
- Add template tags to make the chart dynamic
The Chart Tag Syntax
To declare a chart that will be populated with data dynamically, use these special tags:
foreach
tag in the chart title (opening tag only)x
tags for x-axis valuesy
tags for y-axis values
Sample Data Source
For this tutorial, we’ll use a sales data source:
Creating a Simple Column Chart
Let’s start with a basic column chart showing monthly sales.
Chart Setup
- Insert a column chart in your document
- Set the chart title to:
<<foreach [in sales]>>Monthly Sales
- Add a single series with the name:
<<y [Amount]>>
- Add
<<x [Month]>>
to the chart title after theforeach
tag
How It Works
- The
foreach
tag in the title iterates through your data source - The
x
tag defines what data will appear on the x-axis (months) - The
y
tag defines what data will be displayed as column heights (sales amounts)
C# SDK Implementation Example
Customizing Chart Titles and Labels Dynamically
You can make your charts more informative by dynamically setting titles and labels.
Chart Setup
- Insert a column chart in your document
- Set the chart title to:
<<foreach [in sales]>>Sales for <<[Year]>>
- Add a series with the name:
<<y [Amount]>> in <<[Currency]>>
- Set the x-axis title to:
<<[Period]>>
How It Works
- The expression
<<[Year]>>
in the title is replaced with the year value from your data - The y-axis series name includes both the amount and the currency
- The x-axis title is set dynamically based on the period value (Monthly, Quarterly, etc.)
Python SDK Implementation Example
Excluding Chart Series Conditionally
You can dynamically include or exclude series from your charts based on conditions.
Chart Setup
- Insert a chart with multiple series in your document
- Add the
removeif
tag to any series you want to conditionally exclude - Add the condition inside the
removeif
tag
Example series name with conditional removal:
<<removeif [TotalSales < 10000]>><<y [RegionSales]>>Region A
How It Works
- The
removeif
tag evaluates the condition[TotalSales < 10000]
- If the condition returns
true
, the series is removed from the chart - If the condition returns
false
, the series remains in the chart
Java SDK Implementation Example
Working with Chart Colors
You can dynamically set colors for chart series and individual data points.
Setting Series Colors
Use the seriesColor
tag to define the color of an entire series:
<<seriesColor [colorExpression]>><<y [data]>>Series Name
The color expression can return:
- A string with a known color name (e.g., “red”)
- An integer RGB value (e.g., 0xFF0000 for red)
- A value of the Color type
Setting Point Colors
Use the pointColor
tag to color individual points in a series:
<<pointColor [colorExpression]>><<y [data]>>Series Name
Dynamic Coloring Example
REST API Implementation with cURL
Creating Different Chart Types
GroupDocs.Assembly Cloud supports various chart types. Let’s explore how to create some common ones.
Line Chart Example
Pie Chart Example
Bubble Chart Example
For bubble charts, you’ll need to use the size
tag to define the bubble size:
<<foreach [in data]>><<x [XValue]>><<y [YValue]>><<size [SizeValue]>>Product Performance
Complete Example: Sales Performance Dashboard
Let’s create a comprehensive sales dashboard with multiple charts:
Template Setup
Implementation Using C# SDK
Troubleshooting Common Issues
When working with charts in templates, you might encounter these common issues:
- Chart not showing data - Ensure your
x
andy
tags are properly configured - Missing series - Check that your
removeif
conditions aren’t unintentionally removing series - Incorrect color application - Verify your color expressions return valid values
- Axis scaling problems - Consider using custom axis settings in your original chart template
Tip: Always test your charts with sample data of the same structure and scale as your production data.
What You’ve Learned
In this tutorial, you’ve learned how to:
- Bind charts to dynamic data sources
- Customize chart titles, series, and colors dynamically
- Conditionally include or exclude chart series
- Create different types of charts (column, line, pie, bubble)
- Build comprehensive chart dashboards
Further Practice
To reinforce your learning, try these exercises:
- Create a multi-series line chart showing trends over time with dynamic coloring
- Implement a pie chart that highlights the largest segment with a different color
- Build a column chart with year-over-year comparison and conditional formatting
- Create a dashboard with complementary charts showing different aspects of the same data
Next Tutorial in the Learning Path
Ready to continue your journey? Check out our Tutorial: Working with Other Elements to learn how to work with hyperlinks, bookmarks, checkboxes, and barcodes in your documents.