Instead of using directly Javascript, Charts configuration are
defined through XML tags. Markers can be introduced in templates. Data can also be changed
through XML either manually or using query managers.
The following charts type are available :
Bar charts
Bubble charts
Doughnut charts
Line charts
Pie charts
Polar area charts
Radar charts
Stacked bar charts
Horizontal bar charts
Scatter Line Charts
Charts can also be combined, e.g. a bar chart with a line chart
Tip
SAV Charts is provided with several basic templates and more advanced
templates which simplify the implementation of charts with several sets of data.
The following screenshots are obtained with the provided basic templates.
Screenshots
Bar Chart
Bubble Chart
Doughnut Chart
Horizontal Bar Chart
Horizontal Stacked Bar Chart
Line Chart
Pie Chart
Polar Area Chart
Radar Chart
Scatter Chart
Stacked Bar Chart
Combination Chart
Users Manual
Download the extension and install it in the dependencies
of your site (the extension comes with default sites settings).
Read the tutorial section.
Administration
Important
The flag Allow queries (Admin) must be set by an Admin user in the content
flexform to execute queries.
Warning
This extension generates raw javacript codes from the chart configurations
in the backend.
Most often, simple configurations are taken from the chart.js documentation.
However, more complex configurations can be entered. As said in the TYPO3
Security Guide, "Even if editors do not insert malicious code intentionally,
sometimes the lack of knowledge, expertise or security awareness could put
your website under risk".
Admin users should be careful before granting the rights for backend users
to enter charts.
Marker Tags From TypoScript
Marker tags can be created from TypoScript and used in charts. In the following example
the marker MyMarker takes the value MyValue.
plugin.tx_savcharts.settings.marker.myMarker = TEXT
plugin.tx_savcharts.settings.marker.myMarker.value = MyValue
Copied!
Marker Replacement in Queries
Marker replacement can also be performed in queries. The following
example shows how to define the marker MyMarker associated
with the query whose uid is equal to 1. The marker value MyValue
will replace any marker ###MyMarker### in the query clauses.
plugin.tx_savcharts.settings.customQuery = COA
plugin.tx_savcharts.settings.customQuery.1.MyMarker = TEXT
plugin.tx_savcharts.settings.customQuery.1.MyMarker.value = MyValue
Copied!
Reference
In the following sections all tag attributes can take a value or be a reference to a specific tag.
The allowed syntaxes are:
tag#id. The attribute value will be replaced by the tag whose id is id (tags can be any allowed tag as marker, data, barChart...) .
See for example the provided template barCharts.xml in which there is the following line. The attribute value is replaced by the
marker whose id is labelSet1.
<item key="label" value="marker#labelSet1" />
Copied!
tag#id:integer1. The tag whose id is id must be an array. The attribute value will be replaced by the item at the position given by integer1.
tag#id:integer1-integer2. The tag whose id is id must be an array. The attribute value will be replaced by the sub-array starting at integer1 and ending at integer2.
for#id:value. The tag is replaced by the curent value of the attribute each in the <for> tag.
for#id:key. The tag is replaced by the curent key of the attribute each in the <for> tag.
tag#id:for#idFor:key. The tag whose id is id must be an array. The attribute value will be replaced by the item at the position given by key
of the current each attribute of the <for> tag whose id is IdFor.
tag#id:for#idFor:value. The tag whose id is id must be an array. The attribute value will be replaced by the item at the position given by value
of the current each attribute of the <for> tag whose id is IdFor.
Tip
Examples of such syntaxes can be found in the file Resources/Private/ChartsExamples/BarChartAdvanced.xml
which builds a flexible template able to display upto 9 data sets with 9 different colors in the same charts as explained
in the tutorial section.
Sets the values from a comma separated list of data.
Attributes
values (required): comma separated list of data.
callback
callback
callback
<callback key="callbackKey">callbackFileName.js</callback>
<callback key="callbackKey"><!-- javascript function --></callback>
Copied!
Type
Method
Description
Defines a callback. The javacript function can be provided by means of a file name or
inserted inserted inline inside a XML comment (see the FAQ section for an example).
Attributes
key (required): the key for the callback.
changeToPercentage
changeToPercentage
changeToPercentage
<changeToPercentage />
Copied!
Type
Method
Description
Changes the data to percentage.
Attributes
precision: the precision for rounding floats (default value is 1).
item
item
<item key="myKey" value="tag#id" /> or
<item key="myKey" value="5" /> or
<item key="myKey" values="1, 3, 5" /> or
<item key="myKey">5</item>
Copied!
Type
Method
Description
Sets a data item either by means of a reference, a value or a comma-separated list of values.
Attributes
key (required): the key for the item.
value: if set, the value is defined directly or by the reference, for example data#myDataId.
If value is equal to true or false then a boolean value is generated for this item.
type: if this attribute is equal to function, the value attribute is taken as
the name of a javascript function.
values: if set, a comma-sparated list of values is assumed.
if no value or values attribute is provided, the tag childs can be a value or other <item> tags.
field (required): the field to extract from the query result.
groupby: it set, either the size of the reference defined by the tag and the id, for example "data#myDataId",
or the given integer, will be used to group the data. It means that an new array element will be generated
each time the count is reached. This option is useful to display data when GROUP BY clause is used in the query.
Defines the markerby concatenating the attributes.
Attributes
Any attribute name can be used. The resulting marker is the concatenation of
all attribute values.
In the following exemple, the marker myMarkerId has the value
Number of pages created per year.
<marker id="myMarkerId">
<setMarkerByPieces part1="Number of " part2="pages created " part3="per year" />
</marker>
Copied!
This method is useful when markers include information from a query, for example. In this case,
a part is a reference to the data generated by the query.
Tip
Using \n in an attribute value generates a newline break.
Defines the query manager associated with the query.
Attributes
name (required): Unless you have define you own query manager, use savcharts.
uid (required): The uid of your query. Queries are defined in the backend.
other attributes define markers that can be used in the query clauses. In these clauses ###myMarker### will be
replaced by the value of the marker myMarker. Any attribute
name, except name and uid can be used.
Markers can be directly defined as, for example, myMarker#myValue.
In that case, the marker name will be myMarker and its value is myValue.
Markers can be defined as a reference to a marker tag, for example marker#myMarker.
In that case, the marker name will be myMarker and its value is the value of the marker
whose id is myMarker.
Markers can also be defined as a reference to a specific element in a data or marker array,
for example myMarker#data#myData:0. In that case, the marker name will be myMarker
and its value is obtained from the data with index 0 and whose id is myData.
Loads the XML template file given in the fileName attribute.
Attributes
fileName (required): the file name is relative to the site path.
Tutorial
The processing in SAV Charts is based on the interpretation of XML tags which are
associated with objects. You may split the processing in several XML files or
strings or have all XML tags inserted in the same file.
The SAV Charts extension comes with templates for all chart types.
These templates are in the directory
Resources/Private/Templates/ChartExamples of the extension.
To display a template, simply create a SAV Charts plugin content element in a page.
Then click on the plugin tab.
Fill the template field of the flexform and save.
Important
Use the EXT: prefix to reference the template file from the extension.
Go to the frontend and you should see the following image.
Writing Templates
The templates provided with the extension were adpated from the
examples given in the chart.js documentation.
Let us illustrate the principle for the line chart.
The javascript code to display the line graph is the following:
The template is built by transforming this javascript code into a
XML structure using the <data> tag. By doing so, thanks to the
data tag id, references can be used.
References provide an easy means to split the data and therefore
to make it possible to have them overloaded in the flexform data section or with queries.
The following code is the translation in XML of the previous
javascript code where <data> tags whose id are labels, dataSet1 and dataSet2
can be easily overloaded as explained in the next section.
<data> were inserted inside the <lineChart> tag just by personal choice.
They could have been provided before
the <lineChart> tag. In that case, this tag would have no content
and would simply be written:
Open the plugin in the backend and fill the Data section of the flexform
as follows and save:
Go in the frontend and you should see the following figure.
The principle in SAV Charts is to consider that for a given tag
with a given id the first definition is the first one to use. Therefore, in the
previous example, since <data> tag for id dataSet0 and dataSet1
are defined in the data section, which is
before the template section, they will not be replaced by the
same <data> tags in the template. One may consider
that the <data> tags in the data section overloads the same tags in the template.
It provides a quite simple way of working with generic templates and
adapting their behavior with your real data.
For example, using the same template LineChart.xml, you may want
to display only one curve.
It can simply be done by defining the <data> tag whose id is
dataSets in the data section as shown below.
Enter the previous code in the flexform data section, save and go to the frontend.
Note
In very specific cases you may explicitly allow to overload a given tag
by setting the attribute overload to 1. See
Resources/Private/Templates/ChartExamples/LineChartAdvanced.xml in which this
feature is used to build a flexible template.
Overloading Markers
Markers are tags which can be used to create strings. In the line chart
template two markers are used to define labels
which are displayed in the legend. The markers can be overloaded in the
Markers section of the flexform. Assuming that you have
the previous code to display only one line chart, input the following code in
the Markers sections, save and go to the frontend.
<marker id="labelSet0">Single curve</marker>
Copied!
Options
Options are defined in the chart.js documentation. They can be set by
overloading the <data> tag associated with the options
attribute of the chart. For example, in the LineChart.xml template,
the chart is defined as follows:
A linear interpolation is obtained by setting tension to 0 in
Chart.defaults.global.elements.line
(see chart.js documentation).
Since the global option are in the <data>
whose id is lineChartOptions, nested items whose
keys are elements and line provide acces to Chart.defaults.global.elements.line.
Tip
To generate a boolean value, set the attribute value to true or false.
Using Advanced Templates
More complex templates are provided with SAV Charts. They can display
upto to 9 items in the same charts.
Colors are defined in a specific template DefaultColors.xml
which were chosen to provide constrast between items.
Let us illustrate the use of advanced templates with, for example,
the template LineChartAdvanced.xml.
In the template section enter the following code, save and go to the frontend.
In the marker section, enter the following code, save and go to the frontend.
<marker id="title">A line chart with two curves</marker>
<marker id="labelSet0">Curve 1</marker>
<marker id="labelSet1">Curve 2</marker>
Copied!
Using and Developing Query Managers
Query managers are used in <query> tags to execute queries which can be used in charts.
SAV Charts extension comes with an internal query manager named savcharts which can
deal with TYPO3 database queries as well as queries from other databases.
Using the Query Manager
In the backend in list mode create a new record in a page or a folder.
Select Database if you need to access to an external database,
fill the different fields and save.
Tip
You do not need to create a new database access if you only need
to access to the current TYPO3 database.
Select Query to create a query. Select a database (default is
TYPO3 Database), fill the different clauses and save.
The following figure illustrates the query to display the number of pages per year.
Assuming that the new query has the id 1, the following flexform
configuration displays a bar chart with the
number of pages per year.
In the Queries section, the default query manager savcharts is used.
It calls the query whose uid is 1.
The Data section of the flexform overloads the template to display
only a single barchart
with the data provided by the query, as explained in the section Using Advanced Templates.
Important
The flag Allow queries (Admin) must be set by an Admin user in the content
flexform to execute queries.
Go to the frontend to display the resulting chart.
Developing Your Query Manager
Query managers are implemented by means of hooks.The hook for the internal query manager
is in Classes/Hooks/SavChartsQueryManager.php. This class extends the abstract class
AbstractQueryManager (Classes/Hooks/AbstractQueryManager.php)
which itself implements the interface QueryManagerInterface
(Classes/Hooks/QueryManagerInterface.php).
You can develop your own query manager by providing a hook which must
be added in the file ext_localconf.php
of your extension.
Assuming that your vendor name is MyVendorName and your extension
name is my_extension. Assuming also
that you have written your manager as the class MyQueryManager
in Classes/Hooks/MyQueryManager.php.
Finally, assuming that you want to name your query manager myManager, you should add
the following code in ext_localconf.php of your extension.
You can easily export data associated with any chart using the exportCSV method
associated with the <charts> tag (see exportCsv).
Assuming that you want to export data associated with the line chart template with
a row header containing the x-axis labels and a column header containing the legend labels of
the two curves. Add the following code in the Templates section of the flexform.
Now, in the frontend you should see an icon under the legend.
Click on the icon to open the CSV file.
Frequently Asked Questions
Warning
SAV Charts is now using Chart.js 4.x. Several breaking changes were made in
Chart.js 3.0 and Chart.js 4.0 (see 3.x Migration Guide
and 4.x Migration Guide).
All templates in Resources/Private/Templates/ChartsExamples
were modified to take these changes into consideration.
If you are upgrading Sav Charts, you may have to modify your templates.
You can change the default y-axis (or x-axis) properties using the options for the chart.
For example, assume that the y-axis for the lineChart example has to be changed so that
the minimum is 10, the maximum is 100 and the step is 5.
Add the following configuration in the data section or in your template.
In Chart.js 3.0 , the former xAxes and yAxes arrays in scales were removed.
How to Modify the Tooltip Format?
The tooltip format can be modified using callbacks that are provided with chart.js.
For example let us assume that data provided with the Pie Chart example
are in €. Let us also assume that we want to change the tiptool content
in order to have label - value € instead of the defaut format label:value.
Chart.js library allows to modify several behaviors by means of callbacks.
Please consult the chart.js documentation for details.
The tooltip label can been changed by means of the label callback in tooltip options.
Inline Javascript Function
Add the following configuration in the data section or in your template.
In Chart.js 3.0 tooltips was renamed tooltip and
is now in the plugins item of the options. A tooltip item context is avaible in callbacks.
For more information see the tooltip section
in Chart.js documentation.
Javascript Function in a File
When the javascript function associated with the callback is more complex,
you can also put it in a file and call that file in the callback
as shown in the following configuration.
How to call a JavaScript Function on Events?
The following configuration shows how to associate the JavaScript function
newLegendClickHandler with the onClick event of the legend.
An example which combines a bar chart and a line chart is provided in the directory
Resources/Private/Templates/ChartsExamples. Create a new graph then, in the template
section, enter the following code, save and go to the frontend.
The file ComboChart.xml is very similar to the file BarChart.xml. Only slight changes were made.
The type attribute of the second dataset is set to line and the fill attribute to false.
New tables with their fields are represented with a Black border.
Existing tables are represented with a Dark green border. Only existing fields
uid and pid are shown. If new fields are created, they are shown
in Light blue.
1-n relations are in Dark blue.
n-n relationships are in Dark red with the name of the associated mm table.
Changelog
Version
Changes
14.3.0
Compatibility changed to TYPO3 13.4.x and 14.3.x.
13.4.0
Compatibility changed to TYPO3 12.4.x and 13.4.x.
Version of chart.js changed to 4.4.5.
11.5.0
Compatibility changed to TYPO3 11.5.x.
Version of chart.js changed to 3.6.0.
11.2.0
Compatibility changed to TYPO3 11.2.x.
Version of chart.js changed to 3.2.1.
Scatter graph added with example.
Combination graph example added.
10.4.0
Compatibility changed to TYPO3 10.4.x.
10.3.0
Compatibility changed to TYPO3 10.3.x.
Version of chart.js changed to 2.9.3.
True or false values and use of functions outside callbacks added (issue #1).
9.5.0
Version of chart.js changed to 2.9.2.
Compatibility changed to TYPO3 9.5.x.
Documentation updated to docker.
0.5.0
Version of chart.js changed to 2.7.0.
Compatibility to TYPO3 6.2 removed.
Compatibility changed to TYPO3 9.0.
0.4.0
Version of chart.js changed to 2.7.0.
composer.json added.
Vendor name changed.
0.3.2
Default type for stacked option changed to boolean.
0.3.1
Small bug corrected in the use of file callback functions (thanks to Holger Birkner for reporting this bug).
0.3.0
Processing of callback functions and plugins added.
Documentation updated.
Version of chart.js changed to 2.5.0.
0.2.1
Documentation updated.
Version of chart.js changed to 2.4.0.
Compatibility changed to TYPO3 8.9.
0.2.0
BeginAtZero becomes the default option for line charts.
Subitems may contain data items like setDataFromQuery.
New templates added for horizontal bar charts, horizontal stacked bar charts and
bubble bar charts.
Compatibility changed to TYPO3 8.3.
Version of chart.js changed to 2.2.2
0.1.0
SAV Charts modified for Version 2.1.6 of chart.js
Advanced templates added.
0.0.2
Small changes to remove the use of deprecated methods.
Compatibility changed to TYPO3 8.0.
0.0.1
1st public release.
Sitemap
Index
Reference to the headline
Copy and freely share the link
This link target has no permanent anchor assigned.The link below can be used, but is prone to change if the page gets moved.