score:2
Accepted answer
you can scale the height of the second chart to match the ratio of the # of elements in the two charts.
chart.js requires a container around the canvas to allow dynamic resizing so you'll need to add that to the html also.
i needed to set maintainaspectratio: false
for this to work
// scale second chart based on ratio of data to the first
var fiddlefactor = 1.05; // determined by guesswork. basic ratio is slightly off.
var ratio = data2.labels.length * fiddlefactor / data1.labels.length;
var container1height = parseint(document.getelementbyid("container1").style.height);
// update height of second chart
document.getelementbyid("container2").style.height = container1height * ratio + 'px';
<div id="container1" class="chart-container" style="position: relative; height:300px;">
<canvas id="mychart"></canvas>
</div>
<div id="container2" class="chart-container" style="position: relative; height:300px;">
<canvas id="mychart2"></canvas>
</div>
Source: stackoverflow.com
Related Query
- How to retain spacing between bars for two different bar charts in Chart.js 2
- ng2 charts bar chart need spacing between 2 bars in series Angular
- How to map json array to two different array for chart
- How to show different product name for every bar in chart js
- How do I get a different label for each bar in a bar chart in ChartJS?
- How can I reduce the spacing between my legend and chart proper in my Chart.JS bar chart, and increase it in the graph area?
- Reduce spacing between bars in horizontal bar chart (chart.js)
- How to reduce the gap between bars on bar chart
- Chart.js Bar Chart: How to remove space between the bars in v2.3?
- How to create rounded bars for Bar Chart.js v2?
- Chart.js Bar Chart - how to chart bars from 0
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Different color for each column in angular-chartjs bar chart
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to have solid colored bars in angular-chart bar chart
- PrimeNg bar chart how to show a label for the y-axis
- How to make bar chart animation where all bars grow at the same speed?
- chart js data-point between bar charts
- How to remove bars for those bars with zero value in Chartjs bar chart?
- Vue ChartKick - different colours for bar chart
- how to customize tool tip while mouse go over bars on Chart js bar chart
- Chart.js: How to get x-axis labels to show on top of bars in bar chart
- How to use set the color for each bar in a bar chart using chartjs?
- How can I have different values for the chart and the tooltip in chart.js?
- How to draw baseline for bar chart in chart.js
- Mixed Chart calculating difference between two bars - ChartJS
- Charts.js - Bar chart different colors for value intervals not working
- How to set X coordinate for each bar with react chart js 2?
- Issue with chartjs linear gradient for the mixed bar chart in ReactJS is not calculated for each individual Bars
- How to create spacing between Charts and Legends in Chart.js
More Query from same tag
- getBoundingClientRect gives incorrect value
- How to show bar chart labels clearly using ChartJS?
- set color from datasource like you would set argumentField or valueField?
- After rendering one chart when trying to render a new one chart.js gives "Check that a complete date adapter is provided."
- ChartJS - Display one set of data at a time
- How to install vue-chartkick and use it in my components?
- Tooltip backgroundColor depending on chart color ChartJS
- Dynamically add charts with chart.js
- undefined labels piechart - chartjs
- JSON Data in javascript
- Chart js error in angular: Canvas is already in use. Chart with ID '0' must be destroyed before the canvas can be reused. Fix?
- chart.js on animation end callback
- Adding data to Chart.js line graph from array
- How to use an Aurelia JSPM plugin with WebPack
- Donut Chart : Trigger legend or pie click event while selecting outside filter state change
- Draw line between starting point and Ending point in semi doughnut chart in chart js
- Manipulating data point in chart.js external tooltip
- How to render a vertical line on hover in chartjs
- Charts.js (2.9.4) Gridlines not displaying under Line Graph
- Node.js How to save data from pg database into variable
- Edge browser does not render chart using chart js
- ChartJS canvas not displaying colors in edge browser
- Chart.js - Hide tooltip caret
- Y-Axis with different colors
- Can't display proper time on chart.js timeline
- chartJS line chart not plotting values that are less than minY
- Chart Value of the bar
- JavaScript variable in an object
- ChartJS - format datetime X axis when displaying data from MySql table
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)