4๐
โ
You can simply update options
property like:
options: {
tooltips: {
enabled: false,
},
legend: {
display: false
},
scales: {
xAxes: [{display: false}],
yAxes: [{display: false}],
}
}
And to make it very small, you can put the canvas inside a container div like:
<div class="chart-container">
<canvas id="myChart"></canvas>
</div>
and add some CSS like:
.chart-container {
width: 200px;
}
#myChart {
display: block;
width: 200px;
height: 50px;
}
You can update width
& height
here as per your requirement.
Working Demo:
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 15, 20, 30, 45]
}]
},
// Configuration options go here
options: {
tooltips: {
enabled: false,
},
legend: {
display: false
},
scales: {
xAxes: [{
display: false
}],
yAxes: [{
display: false
}],
}
}
});
.chart-container {
width: 200px;
}
#myChart {
display: block;
width: 200px;
height: 50px;
}
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<div class="chart-container">
<canvas id="myChart"></canvas>
</div>
1๐
You can customize your chart using the options object:
options = { title: { display: false }, legend: { display: false } };
Source:stackexchange.com