how can I put a scale on the right side for mixed chart type with chartjs 3? also how to reduce scale size
See original GitHub issueI am trying to migrate a react app to chartjs3.
I have a mixed, bar chart, linechart:
2 issues with this chart:
- how can I place the bar scale to the right side
- how can I set the maximum of the bar chart to only take 10% of the chart height instead of 100% of the chart height?
code :
`import React, { useState } from ‘react’; import { Line, defaults } from ‘react-chartjs-2’;
const LineChart = () => {
// default values are just for testing
const [dataClose, setDataClose] = useState([21.02, 7.92, 1.73, 3.65, 4.13, 1.36, 3.56, 5.02, 1.85, 1.17, 6.29, 24.07])
const [labels, setLabels] = useState(['2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020'])
const [dataVolume, SetDataVolume] = useState([41000, 28000, 62000, 43000, 36000, 48000, 41000, 28000, 62000, 43000, 36000, 48000])
return (
<div style={{ backgroundColor: "lightblue" }}>
<Line
data={{
labels: labels,
datasets: [
// first dataset
{
// yAxisID:'yLine',
pointRadius: 3,
pointHoverRadius: 4,
lineTension: 0.3,
label: '',
data: dataClose,
backgroundColor: 'black',
borderColor: 'black',
borderWidth: 3, //line thickness
},
{
yAxisID: 'yBar',
type: 'bar',
data: dataVolume,
label: labels,
position: 'right'
}
],
}}
height={200}
width={600}
options={{
// maintainAspectRatio: false, //removes scroll bars
scales: {
y: [
{
id: 'yLine',
display:false,
ticks: {
// beginAtZero: true, //sets the scale minimum to 0
},
},
{
id:'yBar',
ticks: {
// beginAtZero: true, //sets the scale minimum to 0
},
},
],
},
}}
/>
</div>
)
}
export default LineChart`
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Mixed Chart Types - Chart.js
With Chart.js, it is possible to create mixed charts that are a combination of two or more different chart types. A common example...
Read more >Axes | Chart.js
The default scaleId 's for carterian charts are 'x' and 'y' . For radial charts: 'r' . Each dataset is mapped to a...
Read more >Bar Chart | Chart.js
A bar chart provides a way of showing data values represented as vertical bars. It is sometimes used to show trend data, and...
Read more >Cartesian Axes - Chart.js
Cartesian axes are used for line, bar, and bubble charts. ... const config = { type: 'line', data, options: { scales: { x:...
Read more >Line Chart - Chart.js
A line chart is a way of plotting data points on a line. ... Clipping can also be configured per side: clip: {left:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
nvm got it still had the keys nested in
yAxes
which is incorrect, this worksFor me, setting the options as follows:
worked for me.
The current option is set for mixed charts too ( more accurately, I’m using bar and line mixed charts).
The code I’m using for the mixed chart is:
One thing I realized is that the property names are quite different than the charts, so you have to find the options you are looking for one by one I guess.
Hope this helps you out.
@afshinmoshrefi