project_cryptoverse icon indicating copy to clipboard operation
project_cryptoverse copied to clipboard

My Chart is not starting from 0, even though I added "beginAtZero: true"

Open Sreeramsupers opened this issue 3 years ago • 3 comments

This is my code of -

const options = { scales: { yAxes: [ { ticks: { beginAtZero: true, }, }, ], }, };

Sreeramsupers avatar Jan 18 '22 11:01 Sreeramsupers

same issue

imakshay13 avatar Jan 19 '22 19:01 imakshay13

Can you paste the Line.jsx code here?. I will look into it.

Shubham-Rajan avatar Jan 23 '22 22:01 Shubham-Rajan

Can you paste the Line.jsx code here?. I will look into it.

import React from 'react'; import { Line } from 'react-chartjs-2'; import { Col, Row, Typography } from 'antd'; import moment from 'moment';

const { Title } = Typography;

const LineChart = ({ coinHistory, currentPrice, coinName }) => { const coinPrice = []; const coinTimestamp = [];

for (let i = 0; i < coinHistory?.data?.history?.length; i += 1) {
	coinPrice.push(coinHistory?.data?.history[i].price);
}

for (let i = 0; i < coinHistory?.data?.history?.length; i += 1) {
	coinTimestamp.push(moment.unix(coinHistory?.data?.history[i].timestamp).format('DD-MM-YYYY'));
}
const data = {
	labels: coinTimestamp,
	datasets: [
		{
			label: 'Price In USD',
			data: coinPrice,
			fill: false,
			backgroundColor: '#0071bd',
			borderColor: '#0071bd',
		},
	],
};

const options = {
	scales: {
		yAxes: [
			{
				ticks: {
					beginAtZero: true,
				},
			},
		],
	},
};

return (
	<>
		<Row className='chart-header'>
			<Title level={2} className='chart-title'>
				{coinName} Price Chart{' '}
			</Title>
			<Col className='price-container'>
				<Title level={5} className='price-change'>
					Change: {coinHistory?.data?.change}%
				</Title>
				<Title level={5} className='current-price'>
					Current {coinName} Price: $ {currentPrice}
				</Title>
			</Col>
		</Row>
		<Line data={data} options={options} />
	</>
);

};

export default LineChart;

Sreeramsupers avatar Feb 02 '22 03:02 Sreeramsupers