datagovsg-plottable-charts
Motivation
Generating a chart is easy, making it looks beautiful requires much more effort. Numerous charting libraries have been written to solves the basic problem of converting data to chart objects. Regardless of the library you choose, out-of-the-box defaults hardly produces the look you want.
Charts on Data.gov.sg are rendered using the Plottable library. Based on D3, it is highly flexible and gives you many low level controls to fine-tune every single detail. However, this power comes at the price of additional configurations. We want to abstract away these configurations by creating wrappers that pre-apply all the styles we want on our component. That's why we created this library.
What it does for you
Tooltips
Pie chart labels
Automatically downsample tick marks
And many more...
How to use
Dependencies
- D3
- Plottable
- JQuery (optional, only if you require tooltip)
Use with bundler (Webpack, Rollup etc)
npm install --save datagovsg-plottable-charts
import {SimplePie} from 'datagovsg-plottable-charts'
const pie = new SimplePie(props)
pie.mount(document.getElementById('ctn'))
pie.update(newProps)
Using plugins
import {
highlightOnHover,
setupOuterLabel
} from 'datagovsg-plottable-charts/dist/plugins'
highlightOnHover(pie)
setupOuterLabel(pie)
Use without a bundler
<script src="lib/d3.min.js"></script>
<script src="lib/plottable.min.js"></script>
<script src="lib/datagovsg-charts.min.js"></script>
const {SimplePie, plugins} = DatagovsgCharts
const {highlightOnHover, setupOuterLabel} = plugins
const pie = new SimplePie(props)
highlightOnHover(pie)
setupOuterLabel(pie)
Full Component List
Pre-styled
Unstyled
Full Plugin List
Useful helpers
PivotTable
Debugging guide
- Clone the datagovsg/datagovsg-plottable-charts repo
cd
to the cloned repo- Run
npm install
- Change main field in the package.json to
"main": "src/index.js"
- Delete module field in the package.json
- Set up a symlink
sudo npm link
cd
to your working directory- Run
npm link datagovsg-plottable-charts