score:15
i think a solution is to assign a specific property in your chart options for each plugin. each chart will fill a different attribute to use each plugin. in your case, you have plugin1
and plugin2
.
then, in each definition you will check for different attributes to see if that chart is using that plugin or not. for example, your definitions will be something like:
chart.pluginservice.register({
afterdraw: function(chart) {
if (chart.config.options.plugin_one_attribute) {
// plugin code here...
}
}
});
to use this plugin, your chart will have to fill the plugin_one_attribute, in its options. like this:
optionsusingplugin1 = {
plugin_one_attribute: // your variable to be used in the plugin goes here!
responsive: true,
maintainaspectratio: true,
title: {
display: true
}
// and any other config options you are already using
}
and use this when creating your chart:
var mybar = new chart(ctx, {
type: 'bar',
data: data,
options: optionsusingplugin1
});
so, in order to use plugin2, your mybar2 chart will need a specific attribute for plugin2 (which will check for it when registering). this way you can control which plugins will be active in each chart.
hope that helps!
score:4
currently chartjs v2.9.4, from the chartjs documentation, if you have multiple charts, each chart's plugin can be defined in the chart's config, like this:
var ctx = document.getelementbyid("mychart").getcontext('2d');
var chart = new chart(ctx, {
type: 'line',
plugins: [{ //plugin added for this chart
beforeinit: function(chart, options) {
//add statements here
}
}],
options: {
responsive: true, // instruct chartjs to respond nicely.
maintainaspectratio: false
},
// and any other config options as you wish
});
Source: stackoverflow.com
Related Query
- Apply/Register conflicting plugins to different charts
- Chart.js - Line charts with different colors for each border lines
- chart js - Apply different color for each x-axes label
- chartjs - how to set the order in which the different charts are displayed
- How to retain spacing between bars for two different bar charts in Chart.js 2
- How can I load multiple Chartjs charts with different data on the same page?
- How to apply to different bground color for each area in Chart.js
- ChartJS/High Charts Radar chart - Different radial axis labels for each category that appear on hover
- Two charts using same options, but I need different titles for the charts
- Grouped bar charts each group different level in chart.js
- How can I display desired/particular chart in App.vue from Charts.vue which contains different charts in Vuejs
- How to manipulate different charts by angular
- Want to multiple charts on same page with different data
- How do i have a single Chart.vue component instead of different chart components and then display charts from it by changing id of the API
- Error trying to switch between different charts
- Trying to display different types of charts using select/option tag
- Having different colors per bar with angular charts chart.js v2
- Multiple Chart.js charts on a single page, from 1 function but different data
- Chart changes different on zoom when using multiple charts with chart.js and flask
- How to show different tooltips on charts (in columns)?
- multiple chartjs charts with the same configuration but different data
- Switching between different Chart.js charts using the same canvas
- How to run Chart.js samples using source code
- how to not repeat code while creating multiple charts in chart js
- How can I get two stacked chart.js charts to be different types?
- Different color for each bar in a bar chart; ChartJS
- ChartJS Line Charts - remove color underneath lines
- Click events on Pie Charts in Chart.js
- Chart Js Change Label orientation on x-Axis for Line Charts
- ChartJS - Different color per data point
More Query from same tag
- How to set defaults for scales in ChartJS?
- Using Createjs and Chartjs
- How to fix size of mixed chart with bubble chart in Chart.js?
- Svelte , pass data to chartjs from API
- ChartJS Add data from string
- Combining charting with the map
- Add new line in es6 inside a doughnut chart
- How to wrangle JSON data into arrays of unknown name
- Chart.JS Error: this.scale is undefined
- angular-chartjs line chart TypeError: t.merge is not a function
- automatic Y-axis scale: max is always as 120% of highest value in ChartJS
- Chart.js <frame> or <iframe> elements do not have a title
- Chart.js Dynamically Updating Chart with X Axis Time
- Render pie chart datasets out of 100% -- Chart.JS
- Create an interactive custom tooltip for chartjs
- Can I remove the Y-axis counter on chart.js?
- chart.js in mvc graph are not show
- In chartjs format of ticks
- Apply/Register conflicting plugins to different charts
- Chart.js not updating multiple charts independently
- show multiple responsive chart in the same page using chart.js
- Error: "category" is not a registered scale
- chart.js remove lower grid from mixed chart
- ChartJS - Display a single line data in tooltip
- Chartjs render only the last in loop (ionic)
- Is it possible to get chart js data using ajax?
- How to retrieve ChartJS instance after initialization
- Vertical scrubber line using chartjs
- How to add new dataset in line chart of chart.js by iterating over dictionary in JavaScript?
- Why Chart.JS showing an extra line