score:1
You can use the following chart plugin to show/use the same labels/ticks on two different y-axis :
Chart.plugins.register({
beforeInit: function(chart) {
chart.options.scales.yAxes[1].ticks.suggestedMin = Math.min.apply(this, chart.data.datasets[0].data);
chart.options.scales.yAxes[1].ticks.suggestedMax = Math.max.apply(this, chart.data.datasets[0].data);
}
});
- add this at the beginning of your script
Chart.plugins.register({
beforeInit: function(chart) {
chart.options.scales.yAxes[1].ticks.suggestedMin = Math.min.apply(this, chart.data.datasets[0].data);
chart.options.scales.yAxes[1].ticks.suggestedMax = Math.max.apply(this, chart.data.datasets[0].data);
}
});
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
datasets: [{
label: 'LINE',
data: [3, 1, 4, 2, 5],
backgroundColor: 'rgba(0, 119, 290, 0.2)',
borderColor: 'rgba(0, 119, 290, 0.6)',
fill: false
}]
},
options: {
scales: {
yAxes: [{
id: 'y-axis-0',
position: 'left',
ticks: {
stepSize: 1
}
}, {
id: 'y-axis-1',
position: 'right',
ticks: {
stepSize: 1
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>
Source: stackoverflow.com
Related Query
- How to use same data / labels on two y axes in Chart.js
- How do I customize the chart.js tooltip? Two labels have the same data, which I want to show you with each data
- How to use two Y axes in Chart.js v2?
- How to display data labels outside in pie chart with lines in ionic
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to use JSON data in creating a chart with chartjs?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- how can i use chart.js to create a chart that has one time series line and one linear line on it at the same time?
- How to show tooltip value of all data falling on the same axis in chart js?
- How to show the chartjs bar chart data values labels as text?
- How can I get my Chart.JS bar chart to stack two data values together on each bar, and print a calculated value on each bar?
- how to write labels along with data on top and bottom of each stack in bar chart
- How write the labels of the data inside a Doughnut Chart made with Chart.js?
- Two data sets with different time instances on the same ChartJs chart
- Two chart for the same set of data - Chart.js
- How do I destroy/update Chart Data in this chart.js code example?
- How to create a chart.js scatter chart with data from two lists
- ng-charts not updating labels when chart data is updated at same time
- How to add several labels to the same set of data in chartjs?
- How to use a Data Array within a Chart JS dataset?
- Chart.js how to create chart wirhout y-axis for two data sets
- How to customize Data Labels of area chart on ChartJS?
- How to use same backgroundcolors out of an array to unknown data in chartjs?
- How can I make my chart's axes use the same proportions for scaling?
- How to use canvasjs to draw column chart using text data
- How to add data labels in each bar in stacked bar chart in chart.js?
- How to set data values as labels in Chart.js with a Radar Chart
- How can I make two of my lines in Chart JS thicker
- Chart.js how to show cursor pointer for labels & legends in line chart
More Query from same tag
- Chart.js is not rendered until zoom in in angular 8
- Chart.js misreading arrays for labels and axes
- Chart.js dynamically upating data using variable
- Chart.js Using A JavaScript Object
- Change chartType onclick ChartJS
- Change time format in Chart.js date
- Chart.js add border around line chart, and yAxis unit title ([s])
- How can I automatically wrap tooltip text content to multiple lines?
- Change tooltips title at chart.js?
- How do I present progress in an Angular bar chart?
- Chart JS display Data Value on the top of the Bar
- ChartJS : chartjs-plugin-datalabels The value is in the wrong place
- Chart.js; Chart is not showing time and imported data.
- ChartJS 3 vertical annotations
- How to create html id attributes dynamically?
- How to increase space between label and chart area in chart.js
- Can I modify or extend ChartJS?
- Chart.JS Error: this.scale is undefined
- ReferenceError: Chart is not defined - chartjs
- Chart js multiple pie chart on one page
- Making the labels responsive in chart js
- <Canvas is already in use. Chart with ID '18' must be destroyed before the canvas can be reused> in react
- Chart.js how can we have a column not start at 0
- How to sort MMMYY on Chart.Js and display the values that match the month?
- Show dynamic data with dynamic colours in chartjs
- Set custom colours for tooltip squares Chart.js
- flask altering python list
- How to format date parsed from ASPX JSON via AJAX?
- Rails dual axis using Chartkick and chart js
- how do i use the numbers i key in from a form as the input data for chartjs