项目作者: eriklieben

项目描述 :
Aurelia plugin to use chartist
高级语言: JavaScript
项目地址: git://github.com/eriklieben/aurelia-chartist.git
创建时间: 2016-09-10T22:20:35Z
项目社区:https://github.com/eriklieben/aurelia-chartist

开源协议:

下载


aurelia-chartist

Aurelia plugin to use Chartist

Installation

JSPM

Install the package:

  1. jspm i aurelia-chartist

Add the following line to src/main.js or src/main.ts:

  1. export function configure(aurelia: Aurelia) {
  2. aurelia.use
  3. .standardConfiguration()
  4. .feature('resources')
  5. + .plugin('aurelia-chartist');
  6. }

Aurelia-CLI

Install the package(s):

  1. npm i aurelia-chartist chartist --save

Open up the file aurelia_project/aurelia.json and add the following in the bundles, vender-bundle.js dependencies section:

  1. "aurelia-templating-binding",
  2. +{
  3. + "name": "chartist",
  4. + "path": "../node_modules/chartist/",
  5. + "main": "./dist/chartist",
  6. + "resources": [
  7. + "./dist/chartist.min.css"
  8. + ]
  9. +},
  10. +{
  11. + "name": "aurelia-chartist",
  12. + "path": "../node_modules/aurelia-chartist/dist/amd",
  13. + "main": "index"
  14. +},
  15. {
  16. "name": "text",
  17. "path": "../scripts/text"
  18. },

Add the following line to src/main.js or src/main.ts:

  1. export function configure(aurelia: Aurelia) {
  2. aurelia.use
  3. .standardConfiguration()
  4. .feature('resources')
  5. + .plugin('aurelia-chartist');
  6. if (environment.debug) {
  7. aurelia.use.developmentLogging();
  8. }

Usage:

  1. <chartist
  2. data.bind="data"
  3. type="Line"
  4. options.bind="options"
  5. responsive-options.bind="responsiveOptions"
  6. chartist-events="draw.call: animation(data); foobar.call: foobar(data)" ></chartist>
  1. export class App {
  2. public message = 'Hello World!';
  3. public data = {
  4. labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  5. series: [
  6. [1, 5, 2, 5, 4, 3],
  7. [2, 3, 4, 8, 1, 2],
  8. [5, 4, 3, 2, 1, 0.5]
  9. ]
  10. };
  11. public options = {
  12. low: 0,
  13. showArea: true,
  14. showPoint: false,
  15. fullWidth: true,
  16. width: 800,
  17. height: 400
  18. };
  19. public responsiveOptions ={};
  20. public animation(data) {
  21. if(data.type === 'line' || data.type === 'area') {
  22. data.element.animate({
  23. d: {
  24. begin: 2000 * data.index,
  25. dur: 2000,
  26. from: data.path.clone().scale(1, 0).translate(0, data.chartRect.height()).stringify(),
  27. to: data.path.clone().stringify(),
  28. easing: Chartist.Svg.Easing.easeOutQuint
  29. }});
  30. }
  31. }
  32. public foobar(data) {
  33. console.log("foobar", data);
  34. }
  35. }
attribute description on update
data the data property used by chartist uses chartist update method
type type of chart, can be “Line”, ‘Bar”, or “Pie” creates new chartist object
options the options property used by chartist uses chartist update method
responsive-options the responsive-options property used by chartist nothing *
chartist-events custom element used to attach to emitted events nothing

* currently not sure what to do when this changes or if it is supposed to change.

The custom attribute chartist-events allows you to handle any event fired by the eventemitter of chartist.

As seen in the above example, the draw event (a chartist event) will call the method animation and provide it with the data supplied by chartist.

If you installed a plugin for chartist which fires the foobar event, just add it in the same way and it will just work :-)