Graphiques
Vous cherchez la BOEW v3.1?
À partir du 23 septembre 2014, la version 3.1 de la Boîte à outils de l'expérience Web n'est plus supportée. Le code source et la documentation ont été déplacés vers le dépôt wet-boew-legacy.
Needs translation
Purpose
Dynamically generates charts and graphs from table data.
This feature dynamically generates charts from table data. The table data used to generate the graphic need to have a structure as defined in the techniques for tables. The graphic generated can be easily customized by using the CSS Option set to the tables elements.
The charts plugin is a interface between data table and a drawing charts engine. Currently, for extensibility and to ease support, Flot is the charts drawing engine used.
Use when
- To publish a simple or complex charts online
- Before to use an image-based charts approach
- To save time in creating a long text description for your charts
- To have uniform charting style accross your website
Working example
English:
- Charts and graphs - Simple and easy
- Labels and reference values
- Customization, custom presets and multiple charts and graphs types
- Customizing pie charts
- Thousands separator
- Custom preset functions
- Specific test cases
French:
How to implement
- Organize your charts data into a table.
Tips: You can use the techniques for designing tables
- Add a
class="wb-charts"
element to the table.<table class="wb-charts">
- Customize quickly your chart by adding predefined preset, via CSS class name, to the table.
or to series header[{htmlmin-lb}]<table class="wb-charts wb-charts-bar">
<tr> <th class="wb-charts-bar"> [...] <tr> <th class="wb-charts-line"> [...]
Customize your chart
- Configure the plugin using the
data-wb-charts
on thetable
code> element. This parameter allow you configure the options on how your data table will be interpreted in a programmatically determined way.<table class="wb-charts table" data-wb-charts='{ "referencevalue": 1, "labelposition": 1, "noencapsulation": true }'>
- Configure the plugin using the
data-flot
on thetable
code> element. This parameter allow you to set the global Flot options.<!-- The following example configure gradients background color for the grid --> <table class="wb-charts table" data-flot='{ "grid": { "backgroundColor": { "colors" : [ "#000", "#999" ] } } }'>
- Configure the plugin using the
data-flot
on theth
element<!-- The following example configure a specific color for a serie --> <th data-flot='{"color":"#56E"}'>
Beyond your customization
- Create your own preset. Take a look at the Customizing pie charts working example.
- Implement your own function. Take a look at the Custom preset functions working example.
- Extends with other Flot Plugin. Take a look at Pierre Dubois comment on the Github issue
Prioritization of the configuration
- Javascript JSON object passed through global variable
- CSS Preset, will be executed sequentially
- HTML5 data attribute
Preset configuration options
The following is the build in preset available configuration options is specific to wet-charts plugins.
Preset | Inherit | What it does |
---|---|---|
defaults | Sets minimal defaults options for the charts. It contains the instruction to activate the Flot Canvas plugin, the defaults colors array for charting, the defaults function to parse the data content of a table cells. | |
wb-charts-line | Do nothing, here for conviniance and to add more clarity on the charts generated from the data table. | |
wb-charts-area | Customization of a Flot line charts. It's fill the area under the line. | |
wb-charts-bar | Configuration defaults options to create a bars charts. This preset, when detected, will activate the orderbar Flot plugin and set the associated configuration requirement. | |
wb-charts-pie | Default options and activation of the Flot pie chart plugin. It set a default label formater function for the pie chart labels. | |
wb-charts-donut | wb-charts-pie | Build on pie charts preset. It set default options that will transform the pie chart into a donut charts. Also set the pie label formater to use only one decimal precision |
wb-charts-stacked | wb-charts-bar | Only for series. Avoid to be cought and have no impact on how the orderbar plugin will be configured. |
wb-charts-thousandcomma | Replace the function to parse the data content of a table cells in order to support thousand comma separator numbers | |
wb-charts-thousanddot | Replace the function to parse the data content of a table cells in order to support thousand dot separator numbers |
Configuration options
For any configuration options related to Flot, please look at the Flot Reference documentation or/and the pie charts options.
The following configuration options is specific to wet-charts plugins.
Option | Description | How to configure | Values |
---|---|---|---|
reversettblparsing | Define how the data table should be traversed. The default traversal direction is the same as the direction defined in HTML spec. The HTML spec direction is row base. Hold boolean value. | data-wb-charts='{ "reversettblparsing": true }' |
|
labelposition | Specify the row or the column to use to set label on the charts. A vector is a row or column where the direction have no importance. Hold numeric value. | data-wb-charts='{ "labelposition": 1 }' |
|
referencevalue | Specify the row or the column to use as the value of reference to set the steps (x-axis ticks) on the charts. A vector is a row or column where the direction have no importance. Hold numeric value. | data-wb-charts='{ "referencevalue": 1 }' |
|
decimal | For pie charts, it set the number of decimal precision to include for the percentage label. Hold numeric value | data-wb-charts='{ "decimal": 1 }' |
|
nolegend | Ability to destroy the flot generated legend. Hold boolean value. | data-wb-charts='{ "nolegend": true }' |
|
legendinline | Ability to move the flot generated legend after the table to meet WCAG 2.0 Level AA purpose. Hold boolean value. | data-wb-charts='{ "legendinline": true }' |
|
noencapsulation | Wrap or not the table in a details/summary elements. Hold boolean value. | data-wb-charts='{ "noencapsulation": true }' |
|
height | Set the height of a charts. Hold numeric value mesured in pixel. | data-wb-charts='{ "height": 350 }' |
|
width | Set the width of a charts. It may useful for pie charts but are useless for other charts because the Flot Canvas plugin will allow the charts to fit the full width of the table container. Hold numeric value mesured in pixel. | data-wb-charts='{ "width": 350 }' |
|
Events
Document the public events that can be used by implementers or developers.
Event | Trigger | What it does |
---|---|---|
wb-init.wb-charts |
Triggered manually (e.g., $elm.trigger( "wb-init.wb-charts" ); ). |
Used to manually initialize the Charts plugin. Note: The Charts plugin will be initialized automatically unless the required markup is added after the page has already loaded. |
wb-ready.wb-charts (v4.0.5+) |
Triggered automatically after a chart initializes. | Used to identify which chart was initialized (target of the event)
|
wb-updated.wb-charts (v4.0.5+) |
Triggered automatically each time the chart is updated. | Used to identify which chart was updated (target of the event)
|
wb-ready.wb (v4.0.5+) |
Triggered automatically when WET has finished loading and executing. | Used to identify when all WET plugins and polyfills have finished loading and executing.
|
passiveparse.wb-tableparser | When the charts need the table parser to parse the table. When this event is triggered, that means Flot library is loaded. As that said, you can take advantage of this event to load your own Flot plugin. | It will parse the data table and attach the information to a data attribute named tblparser on every elements that related to the table. |
parsecomplete.wb-tableparser | When the table parser has completed his parsing job. | It's means that the tblparser data attribute is now ready to be use. So it is after this event that the data will be prepared for Flot. Then the charts will be created. |
Source code
- Core: Charts plugin
- Dependency: Complex Table Parser
- Dependency: Flot
- Flot Pluging third party dependency: SideBySideImproved
- Date de modification :