chartist-plugin-htmllabels

0.4.0 • Public • Published

chartist-plugin-htmllabels

Bringing back HTML labels for Chartist charts.

Since Chartist version 0.11 you could no longer use HTML like '<a href="/some/link">' + text + '</a>' for the labels, chartist would use textContent instead of innerHtml for displaying the labels and the markup would be displayed.

This plugin brings back that possibility - just call the plugin in your plugins array and you can use HTML again.

All credit for the plugin itself goes to @gionkunz (see his code here in an issue). I just added the HTML sanitizer and wrapped it in a npm package.

Install

$ npm install chartist-plugin-htmllabels --save

Usage

In an example chart:

require('chartist-plugin-htmllabels');

var chart = new Chartist.Line('.chart', {
  labels: ['<a href="#">1</a>', '<a href="#">2</a>', '<a href="#">3</a>', '<a href="#">4</a>', '<a href="#">5</a>'],
  series: [
    [1, 2, 3, 5, 8]
  ]
}, {
  axisY: {
    scaleMinSpace: 40,
    labelInterpolationFnc: function(value, index) {
      return '<strong>Value:</strong>' + value + '<br>' + 
        '<strong>Index:</strong>' +index
    },
    offset: 80
  },
  plugins: [Chartist.plugins.htmllabels()]
});

Package Sidebar

Install

npm i chartist-plugin-htmllabels

Weekly Downloads

4

Version

0.4.0

License

MIT

Unpacked Size

9.23 kB

Total Files

7

Last publish

Collaborators

  • bastihilger