project_cryptoverse
project_cryptoverse copied to clipboard
My Chart is not starting from 0, even though I added "beginAtZero: true"
This is my code of -
const options = { scales: { yAxes: [ { ticks: { beginAtZero: true, }, }, ], }, };
same issue
Can you paste the Line.jsx code here?. I will look into it.
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;