1👍
type
is not an attribute of options
but it belongs to the higher level configuration
object.
All attributes inside options
are optional. I didn’t find this information in chart.js documentation but in the TypeScript type definitions repository that contains the specification of the interface ChartOptions
in the file types/chart.js/index.d.ts
.
Below code snippet from https://www.chartjs.org/docs/latest/getting-started/ illustrates that it’s fine to provide an empty options
object or no options
at all.
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
type: 'line',
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, 2, 20, 30, 45]
}]
},
options: {} // may be omitted
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart" height="80"> </canvas>
Source:stackexchange.com