Creating Charts with FME | ChartGenerator

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2022.0


Charts are an excellent way to visually communicate data that would otherwise be presented in a text-based format. Colour, chart type, and labels can be customized to make data appear in an attractive way to your client or target audience.

The best type of chart to use depends on the nature of the data: Pie Charts are best for displaying data that is shared among a total, such as budget allowances and election results; Bar Charts are best for comparing data spread across categories, such as monthly sales for different departments; Histograms or Scatter Plots are best for showing the distribution of data over one or two variables and can help to identify correlations.

FME's ChartGenerator transformer allows you to create custom Line, Scatter, Pie, Bar, and Histogram charts from the data in your workspace. The parameters dialog allows you to customize the chart appearance and displays a preview of the chart using arbitrary sample data.

ChartGenerator Parameters.png

Data values for the chart are specified from attributes, where each attribute defines a data series and each feature provides a value in the data series. The sum of all input features produces either a single raster chart or one per group if Group By is enabled. Data values can also be specified from list attributes, where each feature represents a chart and each list attribute on the feature represents a data series in the chart.

The transformer outputs raster charts in the form of raster geometries on the features. Rasters can then be written to an image format like PNG or JPEG, or incorporated into a report using the corresponding FME writer, like PDF or Excel.

Step-by-Step Instructions

This example creates a pie chart using municipal election data from a simple CSV (Comma Separated Value) file that contains candidate names and the number of votes per candidate.

1. Generate a new workspace

Open FME Workbench and generate a new workspace. The source election data is a CSV file and the output chart will be a PNG image, so enter the following parameters:

  • Reader Format: CSV (Comma Separated Value)
  • Reader Dataset: <Tutorial Download>/ElectionResults.csv
  • Writer Format: PNG (Portable Network Graphics)
  • Writer Dataset: <Tutorial Download>/output

Screen Shot 2021-10-15 at 11.31.28 AM.png
Click OK to generate the workspace.

2. Add transformers to prepare the data
When using the ChartGenerator, source data often needs to be prepared or reformatted before using it to create a chart. In this example, we will use the Sorter transformer to sort the features based on the vote count. The candidate with the highest number of votes will appear first, which means we can then use the "Explode Slice" option in the ChartGenerator to highlight the winning candidate in a visually pleasing way.

Click the canvas and type "Sorter". Add this transformer to the workspace and connect it between the reader and writer feature types.

Screen Shot 2021-10-15 at 11.35.33 AM.png

Double-click the Sorter to open the parameters. Under "Sort By", specify the Votes attribute, Numeric, and Descending. This will configure the transformer to sort the features by the number of votes, with the highest number first.

Screen Shot 2021-10-15 at 11.33.50 AM.png
Click OK.

3. Add and configure a ChartGenerator

Add a ChartGenerator transformer and connect it between the Sorter and the writer feature type. Double-click it to open its parameters. We will create a Pie Chart from the number of votes and use the candidate names as labels. Set the following parameters:

Chart Settings

  • Type: Pie
  • Title: Election Results
  • Legend: Checked
  • Placement: Outer Upper Right
  • Feel free to also customize the fonts for your chart in this section!

Data Series

  • Data Attribute: Votes
  • Label Attribute: Candidate
  • Color Scheme: Rainbow
  • Show Percentages: Yes
  • Effects: Explode Slice

Screen Shot 2021-10-18 at 10.18.25 AM.png

Tip: Check the ChartGenerator documentation for full details on how to set all of the transformer parameters.

The workspace is now configured to write the chart to a PNG file. You could also write the chart to a different format, a PDF, an Excel file, or another format that supports rasters.

Double-click the writer feature type and rename it to whatever you want your output PNG file to be named. The final workspace will look like this:

Screen Shot 2021-10-15 at 11.42.08 AM.png

4. Run the workspace
Run the workspace and view the output file in the destination folder you specified.

The output PNG should look like this:

ElectionResults 10.18.52 AM.png

Preparing data for the ChartGenerator

The above example uses a Sorter to prepare data for the ChartGenerator. Other transformers that might be helpful to add before a ChartGenerator include the StatisticsCalculator (to create a chart based on calculated statistics, e.g. percent distribution), AttributeManager, and other attribute transformers.

Open the attached workspace called ElectionResults_Advanced.fmwt for an example of how to use a series of transformers to reformat more complex input data. In that example, the source CSV file contains more data, including voting districts as column headers. We use Attribute* transformers to rearrange the spreadsheet so the data is more accessible and efficient for use by the ChartGenerator. We also add a user parameter to ask the end user which voting district they want to see a pie chart for.

The data preparation part of that workspace looks like this:

Screen Shot 2021-10-15 at 11.44.55 AM.png

Additional Resources

Data Attribution

The data used here originates from data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.

Was this article helpful?



Please sign in to leave a comment.