{"id":17566613,"url":"https://github.com/glavin001/ember-c3","last_synced_at":"2025-04-07T07:18:43.642Z","repository":{"id":399432,"uuid":"20110831","full_name":"Glavin001/ember-c3","owner":"Glavin001","description":":chart_with_upwards_trend: Ember addon library for C3, a D3-based reusable chart library.","archived":false,"fork":false,"pushed_at":"2022-06-16T21:32:24.000Z","size":13120,"stargazers_count":80,"open_issues_count":4,"forks_count":58,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-07T07:18:38.571Z","etag":null,"topics":["c3","chart","d3","ember","javascript"],"latest_commit_sha":null,"homepage":"http://glavin001.github.io/ember-c3/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Glavin001.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-23T19:03:08.000Z","updated_at":"2025-03-17T15:12:13.000Z","dependencies_parsed_at":"2022-08-16T10:25:08.594Z","dependency_job_id":null,"html_url":"https://github.com/Glavin001/ember-c3","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavin001%2Fember-c3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavin001%2Fember-c3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavin001%2Fember-c3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glavin001%2Fember-c3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Glavin001","download_url":"https://codeload.github.com/Glavin001/ember-c3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608160,"owners_count":20965953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c3","chart","d3","ember","javascript"],"created_at":"2024-10-21T15:06:44.253Z","updated_at":"2025-04-07T07:18:43.614Z","avatar_url":"https://github.com/Glavin001.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ember-C3\n\n[![npm version](https://badge.fury.io/js/ember-c3.svg)](http://badge.fury.io/js/ember-c3)\n[![Ember Observer Score](https://emberobserver.com/badges/ember-c3.svg)](https://emberobserver.com/addons/ember-c3)\n[![Join the chat at https://gitter.im/Glavin001/ember-c3](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Glavin001/ember-c3?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nEmber component library for\n[C3, a D3-based reusable chart library](https://github.com/masayuki0812/c3).\n\n**See the demo [here](http://glavin001.github.io/ember-c3/)**\n## Compatibility\n\n* Ember.js v3.13 or above\n* Ember CLI v3.24 or above\n* Node.js v12 or above\n* ember-auto-import \u003e= 2 (BREAKING CHANGE!)\n* Embroider compatabile\n\n## Installation\n\n```shell\nember install ember-c3\n```\n\n## Usage\n\nComponent usage and properties are [below](#basic). The code for these example\ncharts and more is in the\n[dummy app source code](https://github.com/Glavin001/ember-c3/tree/master/tests/dummy/app).\n\n---\n\n| Combination                                                                                                   |\n| ------------------------------------------------------------------------------------------------------------- |\n| ![image](https://cloud.githubusercontent.com/assets/1885333/9792404/4e750a06-57b6-11e5-96c1-8a6cabdef4ac.png) |\n\n| Timeseries                                                                                                                    |\n| ----------------------------------------------------------------------------------------------------------------------------- |\n| ![ember-c3-timeseries-4](https://cloud.githubusercontent.com/assets/1885333/9792600/6032061c-57b7-11e5-9a2c-80e680d274a5.gif) |\n\n| Gauge                                                                                                                    | Pie                                                                                                                    | Donut                                                                                                                    |\n| ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |\n| ![ember-c3-gauge-2](https://cloud.githubusercontent.com/assets/1885333/9792503/c7ebc05a-57b6-11e5-8d43-116e9dd7c368.gif) | ![ember-c3-pie-1](https://cloud.githubusercontent.com/assets/1885333/9792639/8f90f5ee-57b7-11e5-859c-9a083255df4a.gif) | ![ember-c3-donut-1](https://cloud.githubusercontent.com/assets/1885333/9792665/ad4a6ee4-57b7-11e5-90d4-df152b24e4a3.gif) |\n\n### Basic\n\nWhere `this.model` is your C3 data and chart options:\n\n```handlebars\n\u003cC3Chart @data={{this.model}} /\u003e\n```\n\n### Advanced\n\nSee http://c3js.org/examples.html for examples of how to use C3.\n\n### Component Arguments\n\nThe arguments match the corresponding C3 options found in the\n[C3 Documentation](https://c3js.org/gettingstarted.html#generate). As\ndocumented, most C3 settings (i.e. bar, axis, size, etc) can be included in the\ndata object.\n\nArguments break out the settings to simplify chart configuration. Note: The\nchart type **must be** assigned in the chart `data` object.\n\nProperties marked with an asterisk (\\*) will update the chart when the property\nchanges. See examples in the dummy app.\n\n| Property               | Description                                                                                                                                                                                                                                 | Example                             |\n| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |\n| c3chart                | Assigns the generated C3 chart object to the passed property. Any C3 API method can be used with this property                                                                                                                              | chart.hide(\"data1\")                 |\n| data\\*                 | C3 data [object](https://c3js.org/gettingstarted.html#generate). `data` is mutable after the chart is created                                                                                                                               |                                     |\n| axis\\*                 | C3 axis [object](https://c3js.org/reference.html#axis-rotated). See C3 examples for combining with data object. Chart axis are mutable after the chart is created                                                                           |                                     |\n| bar                    | Used to assign bar chart [properties](https://c3js.org/reference.html#bar-width)                                                                                                                                                            |                                     |\n| pie                    | Used to assign pie chart [properties](https://c3js.org/reference.html#pie-label-show)                                                                                                                                                       |                                     |\n| donut                  | Used to assign donut chart [properties](https://c3js.org/reference.html#donut-label-show)                                                                                                                                                   |                                     |\n| gauge                  | Used to assign gauge chart [properties](https://c3js.org/reference.html#gauge-label-show)                                                                                                                                                   |                                     |\n| line                   | Used to assign line chart [properties](https://c3js.org/reference.html#line-connectNull)                                                                                                                                                    |                                     |\n| area                   | Used to assign area chart [properties](https://c3js.org/reference.html#area-zerobased)                                                                                                                                                      |                                     |\n| point                  | Used to assign data point [properties](https://c3js.org/reference.html#point-show)                                                                                                                                                          |                                     |\n| grid                   | Used to show, hide and modify the graph grid. See [docs](https://c3js.org/reference.html#grid-x-show)                                                                                                                                       |                                     |\n| legend                 | Show, hide and modify the legend position. See [docs](https://c3js.org/reference.html#legend-show)                                                                                                                                          |                                     |\n| tooltip                | Show, hide and modify the tooltip. See [docs](https://c3js.org/reference.html#tooltip-show)                                                                                                                                                 |                                     |\n| subchart               | Show, hide and modify C3 sub charts. See [docs](https://c3js.org/reference.html#subchart-show)                                                                                                                                              |                                     |\n| zoom                   | Set C3 zoom features. See [docs](https://c3js.org/reference.html#zoom-enabled)                                                                                                                                                              |                                     |\n| size                   | Control chart size. See [docs](https://c3js.org/reference.html#size-width)                                                                                                                                                                  | size: {width: 640 }                 |\n| padding                | Set padding around graph. See [docs](https://c3js.org/reference.html#padding-top)                                                                                                                                                           | padding: { top: 20}                 |\n| title                  | Set chart title                                                                                                                                                                                                                             | title: { text: \"This is my chart\" } |\n| interaction            | Enable or disable [interactions](https://c3js.org/reference.html#interaction-enabled)                                                                                                                                                       | interaction: { enabled: false }     |\n| color\\*                | Used to assign color [properties](https://c3js.org/reference.html#color-pattern). Chart colors are mutable after chart creation                                                                                                             |                                     |\n| dtitle                 | Dynamically change the chart title. See details below                                                                                                                                                                                       |                                     |\n| transition             | Equivalent to [transition.duration](https://c3js.org/reference.html#transition-duration). Default duration is 350ms. Transition times less than 300ms may not render properly. Use chart.load() and .unload() if shorter times are required |                                     |\n| unloadDataBeforeChange | When set to true existing data will be unloaded before new data is loaded. Useful for pie and donut chart data changes. You can manually load/unload data using chart.load() and chart..unload()                                            |\n\n### dtitle\n\nThe `dtitle` property is used to dynamically change a chart's title. C3 doesn't\nnatively support this without forcing a chart redraw which can cause side\neffects.\n\nThe title can be set by targeting the `.c3-title` class but that doesn't provide\nabstraction from C3's internals.\n\n`dtitle` gives you some control over side effects using a parameter to control\nhow the graph is refreshed. An object with the new title and a `refresh`\nparameter is used to indicate whether all properties should be refreshed or only\nthe chart title.\n\nSetting `refresh` to false will only refresh the title and ignore changes to the\ndata, colors and axis properties. A short example is below. See the drill down\nexample in the dummy app to see how `dttile` is used and potential side effects.\n\nThe chart's initial title is set using the `title` parameter.\n\n```handlebars\n\u003cC3Chart\n  @data={{this.graphData}}\n  @title={{this.title}}\n  @dtitle={{this.dtitle}}\n/\u003e\n\n\u003cbutton {{on 'click' this.changeTitle}}\u003eChange Title\u003c/button\u003e\n```\n\n```javascript\nimport Controller from '@ember/controller';\nimport { action } from '@ember/object';\nimport { tracked } from '@glimmer/tracking';\n\nexport default class ApplicationController extends Controller {\n  @tracked title = { text: 'Coffee Brewing' };\n  @tracked dtitle;\n\n  get graphData() {\n    return {\n      columns: [\n        ['Cold Brewed', 12],\n        ['Drip', 67],\n        ['French Press', 14],\n        ['Iced', 38],\n        ['Percolated', 64]\n      ],\n      type: 'pie'\n    };\n  }\n\n  @action\n  changeTitle() {\n    this.dtitle = { text: 'Making coffee!', refresh: false };\n  }\n}\n```\n\n### C3 Methods\n\nIf you assign a controller property to the c3chart property, you can use most of\nC3's api [methods](https://c3js.org/reference.html#api-focus). Not all the\nmethods have been tested.\n\n```handlebars\n{{! templates/application.hbs }}\n\u003cC3Chart @data={{this.baseData}} @c3chart={{this.chart}} /\u003e\n\n\u003cbutton {{on 'click' this.loadUS}}\u003eUS Cars\u003c/button\u003e\n\u003cbutton {{on 'click' this.loadGerman}}\u003eGerman Cars\u003c/button\u003e\n\u003cbutton {{on 'click' this.resetData}}\u003eReset\u003c/button\u003e\n```\n\n```javascript\n// controllers/application.js\nimport { action } from '@ember/object';\nimport Controller from '@ember/controller';\n\nexport default class ApplicationController extends Controller {\n  chart = null;\n\n  baseData = {\n    columns: [\n      ['US', 64],\n      ['German', 36]\n    ],\n    type: 'donut'\n  };\n\n  modelsGerman = [\n    ['Mercedes', 12],\n    ['Volkswagon', 54],\n    ['BMW', 34]\n  ];\n\n  modelsUS = [\n    ['Ford', 35],\n    ['Chevy', 26],\n    ['Tesla', 2],\n    ['Buick', 10],\n    ['Dodge', 27]\n  ];\n\n  @action\n  resetData() {\n    this.chart.load(this.baseData);\n    this.chart.unload([\n      'Mercedes',\n      'Volkswagon',\n      'BMW',\n      'Ford',\n      'Chevy',\n      'Tesla',\n      'Buick',\n      'Dodge'\n    ]);\n  }\n\n  @action\n  loadUS() {\n    this.chart.load({ columns: this.modelsUS });\n    this.chart.unload('US', 'German');\n  }\n\n  @action\n  loadGerman() {\n    this.chart.load({ columns: this.modelsGerman });\n    this.chart.unload('US', 'German');\n  }\n}\n```\n\n### C3 Events\n\nC3 emits two types of events - [chart](https://c3js.org/reference.html#oninit)\nand [data](https://c3js.org/reference.html#data-onclick) events. Chart events\nare assigned callback functions using component arguments.\n\nData events **must** be assigned to an `action` in the data object.\n\nChart events supported by `ember-c3`.\n\n| Events      | Description                                 | Example                         |\n| ----------- | ------------------------------------------- | ------------------------------- |\n| oninit      | Triggered when chart is initialized         | @oninit={{this.init}}           |\n| onrendered  | Triggered when chart is rendered or redrawn | @onrendered={{this.render}}     |\n| onmouseover | Triggered when mouse enters the chart       | @onmouseover={{this.mouseover}} |\n| onmouseout  | Triggered when mouse leaves the chart       | @onmouseout={{this.mouseout}}   |\n| onresize    | Triggered when screen is resized            | @onresize={{this.resize}}       |\n| onresized   | Triggered when resizing is completed        | @onresized={{this.resized}}     |\n\nCallback functions will receive the `C3` chart object which can be used to\nmodify the chart or as data source for other operations. The `@oninit` event\ndoes not receive the chart object because the chart has not been created yet.\nSee the chart events example can be used in the dummy app.\n\nC3 data events such as `onclick`, `onmouseover` and `onmouseout` are assgined\ncallback functions in the chart configuration or data settings. Data events\nsupply the data names and values based on mouse location.\n\nA data event example is shown below. Note that data callbacks require `bind`.\nSee the dummy app for more examples.\n\n```handlebars\n{{! templates/application.hbs }}\n\u003cC3Chart @data={{this.data}} @oninit={{this.setup}} /\u003e\n```\n\n```javascript\n// controllers/application.js\nimport { action } from '@ember/object';\nimport Controller from '@ember/controller';\nimport { bind } from '@ember/runloop';\n\nexport default class ApplicationController extends Controller {\n  get data() {\n    // iris data from R\n    return {\n      columns: [\n        ['data1', 30],\n        ['data2', 120],\n        ['data3', 10],\n        ['data4', 45],\n        ['data5', 90]\n      ],\n      type: 'pie',\n      // override component onclick event handler\n      // bind is required for data events\n      onclick: bind(this, this.onClick)\n    };\n  }\n\n  // oninit chart event\n  @action\n  setup() {\n    console.log('chart inited');\n  }\n\n  // data event - triggered when pie slice is clicked\n  onClick(data, elem) {\n    alert(`Data ${data.name} has a value of ${data.value}`);\n  }\n}\n```\n\n### Accessing D3\n\nYou can use the D3 library in your application by importing it where needed\n\n```javascript\nimport d3 from 'd3';\n```\n\nSee the D3\n[example](https://github.com/Glavin001/ember-c3/blob/master/tests/dummy/app/controllers/d3.js)\nin the dummy app.\n\n### Helpful Links\n\n- [Extending ember-c3 charts using base-component approach](https://medium.com/nimbo-x-development/extending-ember-c3-charts-using-base-component-approach-78df1d635050#.k8j8gnnqa)\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglavin001%2Fember-c3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglavin001%2Fember-c3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglavin001%2Fember-c3/lists"}