This is an ember-cli wrapper for Chartist.It allows you to render Chartist charts in your templates using components.
package.json
.In an existing ember-cli project. Install with:
ember install ember-cli-chartist
In the template where you want the chart to appear:
<ChartistChart @type="line" @data={{model.chartData}} />
data
is an optional attribute. Its value should be an object. Check theChartist docsfor expected data structure.type
is a required attribute. It can be any of the recognized chat types.The data can be specified in an Ember route or controller. In the example above it's coming from the model which is defined in the route.
/app/routes/application.js
import Route from '@ember/routing/route';
export default class ApplicationRoute extends Route {
model() {
return {
chartData: {
labels: ['Day1', 'Day2', 'Day3'],
series: [
[5, 4, 8],
[10, 2, 7],
[8, 3, 6]
]
}
}
}
};
There are three types of charts; line, bar, and pie. The default is line. You can change the chart type using the type
attribute.
/app/templates/application.hbs
<ChartistChart @type="bar" @data={{model.chartData}} />
Chartist charts scale up and down in size. They do so at specified ratios. You can change the ratio using the ratio
attribute.
/app/templates/application.hbs
<ChartistChart @ratio="ct-golden-section" @data={{model.chartData}} />
See Chartist docsfor the full list of ratios and info on how to create your own.
Chartist charts have a whole bunch of cool configuration options. You can passthose to the chartist-chart
components with the options
attribute. You'llneed to create the options object in a similar way as you do for the data
attribute object.
/app/templates/application.hbs
<ChartistChart @options={{chartOptions}} @data={{model.chartData}} />
/app/controllers/application.js
import Controller from '@ember/controller';
export default ApplicationController extends Controller {
chartOptions = {
showArea: true,
lineSmooth: false,
axisX: {
showGrid: false
}
};
};
See the Chartist docsfor all available config options. There's bunch of good-uns!
You can also configure your charts based on media queries. The sameconfiguration options are available, but you provide them via the responsiveOptions
attribute. They can be used in tandem with standard options
.
<ChartistChart @responsiveOptions={{chartResOptions}} @data={{model.chartData}} />
/app/controllers/application.js
import Controller from '@ember/controller';
export default ApplicationController extends Controller {
chartResOptions = [
['screen and (min-width: 640px)', {
showArea: true,
lineSmooth: false,
axisX: {
showLabel: false
}
}]
];
};
There are other ways to configure chartist-chart components that are specific tothe addon.
updateOnData
: By default, when the data associated with a chartist-chart ischanged, the chart will be updated to reflect the data. That can be turned offby setting updateOnData to false. Note: If you use this option, you will haveto manually draw and redraw the chart using Chartist methods.
<ChartistChart @updateOnData={{false}} />
If you want to use custom CSS you can tell the addon to not include the compiled version.
In your app's ember-cli-build.js
:
let app = new EmberApp({
'ember-cli-chartist': {
'useCustomCSS': true
}
});
If you use custom CSS, you'll likely want to import the Chartist Scss into yourapp's scss, you will need to install ember-cli-sass.You can then import the Chartist scss with:
In app.scss
@import "chartist/chartist.scss";
you can also import the Chartist settings scss:
@import "chartist/chartist-settings.scss";
For more on custom styles see the Chartist docs
chartist-chart
Care has been taken to provide as many knobs and parameters as you'd need to NOTextend the <ChartistChart
component. Pass in data you need. The component doesyield its template above the chart.
Should you find yourself needing to extend the base class please open an issue.
yarn add -D chartist-plugin-fill-donut
ember-cli-build.js
import your plugin, e.g. app.import('node_modules/chartist-plugin-fill-donut/dist/chartist-plugin-fill-donut.js');
chartOptions
object add the plugin, e.g.chartOptions = {
plugins: [
Chartist.plugins.fillDonut({
// config of plugin
})
],
};
There is an example app included in this repo in /tests/dummy/
. It contains examples of most of the functionality described above. To view thoseexamples you'll need to clone this repo and start the Ember cli server.
git clone https://github.com/jherdman/ember-cli-chartist.git
cd ember-cli-chartist
ember serve
The example app will be running at http://localhost:4200
Asserting on characteristics of your chart is kind of hard as it's an SVGrendering. Tools like Percy may be of help with ensuring your chart looks the wayit should. We do have an issue openand are interested in pull requests to help with this matter.
Consider, however, that your chart may be difficult to read for people that arevisually impaired. Consider implementing anaccessible data table —these are vastly easier to make assertions on. Note that we do not provide toolingfor this as it's out of scope for this library, and is probably too close to yourbusiness domain to meaningfully abstract.
If you'd like to contribute to this project, that would be swell. Here are some details on doing that.
git clone
this repositoryyarn install
ember server
yarn lint:js
yarn lint:js -- --fix
yarn lint:hbs
ember test
ember test --server
Ember CLI 是一个 Ember.js 命令行工具,提供了由 broccoli 提供的快速的资源管道和项目结构。 Ember CLI 基于 Ember App Kit Project 目前已经废弃。 Assets Compilation Ember CLI asset compilation is based on broccoli. Broccoli has support for: Ha
This repository is no longer maintained. As a replacement check out: https://github.com/sir-dunxalot/ember-tooltips Ember CLI Tooltipster An Ember CLI add-on that wraps Tooltipster into an ember compo
ember-cli-updater This ember-cli addon helps you update your ember-cli application or addon. The idea of this addon is to automate some parts of the upgrade process so it's simplified. Not every chang
Ember-cli-yadda This Ember CLI addon facilitates writing BDD tests in the Gherkin language and executing them against your Ember app. @mschinis (Micheal Schinis) Did a great talk at @emberlondon BDD a
Ember-cli-simditor Ember component wrapper for simditor. Changes 0.0.7 Different from previous version, you must wrap content in object. See issue 6 for why. Getting Started Installation In your ember
ember-cli-chai Chai assertions for Ember.js. Deprecated This package is deprecated. Please use ember-auto-import to use chai and chai plugins directly. If you'd like to use chai, or were previously us
ember-cli-storybook �� Ember storybook adapter Compatibility Ember.js v3.16 or above Ember CLI v2.13 or above Node.js v10 or above Installation ember install @storybook/ember-cli-storybook Usage This
ember-cli-daterangepicker Just a simple component to use daterangepicker. ❗ Important notice The use of this addon is no longer recommended. This addon is a very simplewrapper for another JS library t