Skip to content

how can I put a scale on the right side for mixed chart type with chartjs 3? also how to reduce scale size #676

Open
@afshinmoshrefi

Description

@afshinmoshrefi

I am trying to migrate a react app to chartjs3.

I have a mixed, bar chart, linechart:
image

2 issues with this chart:

  1. how can I place the bar scale to the right side
  2. 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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions