score:0
Accepted answer
here's your solution,
chart.register(chartdatalabels);
chartlabels = ["mar 2020", 'mar 2021', 'apr 2022']
data = [75, 60, 80]
data2 = [80, 82, 85]
var data = {
labels: chartlabels,
datasets: [
{
type: 'line',
label: 'sales growth',
data: data,
backgroundcolor: 'rgb(10,255,255)',
bordercolor: 'rgb(0,0,0)',
borderwidth: 1.5,
linetension: 0.6,
}
]
}
var data2 = {
labels: chartlabels,
datasets: [
{
type: 'line',
label: 'sales growth',
data: data2,
backgroundcolor: 'rgb(10,255,255)',
bordercolor: 'rgb(0,0,0)',
borderwidth: 1.5,
linetension: 0.6,
}
]
}
var options = {
layout: {
padding: 40
},
elements: {
point: {
hoverradius: 5
}
},
plugins: {
legend: {
display: false
},
datalabels: {
color: 'black',
anchor: 'end',
align: 'top',
formatter: (v, cat) => {
let label = cat.chart.data.labels[cat.dataindex];
if (label != 'ttm') {
label = '' + label;
}
return label + '\n ' + v;
},
border: true
}
},
scales: {
y: {
display: false,
grid: {
display: false,
linewidth: 3
}
},
x: {
display: false,
grid: {
display: false,
}
}
}
}
var cat = document.getelementbyid('1st_year').getcontext('2d');
var mychart = new chart(cat, {
data: data,
options: options
});
var cat2 = document.getelementbyid('2nd_year').getcontext('2d');
var mychart2 = new chart(cat2, {
data: data2,
options: options
});
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="container">
<div class="row mt-2">
<div class="col-lg-3 col-md-6 col-sm-12 border rounded text-center">
<h6 class="mb-4 mt-2">average of 1st year student's</h6>
<canvas id="1st_year"></canvas>
</div>
<div class="col-lg-3 col-md-6 col-sm-12 border rounded text-center">
<h6 class="mb-4 mt-2">average of 2nd year student's</h6>
<canvas id="2nd_year"></canvas>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.0.0/chartjs-plugin-datalabels.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Source: stackoverflow.com
Related Query
- how to not repeat code while creating multiple charts in chart js
- How to pass an array to chart.js data:[] while creating a chart in php
- How to save Chart JS charts as image without black background using blobs and filesaver?
- how to create multiple chart on one component vue
- Multiple charts on same page not working - ng2-charts
- How to use chart.js script to draw multiple pie Charts
- How do I keep chart.js charts in one JS file, and not get errors when the ID from the JS file don't exist on one specific html page?
- How to align multiple pie charts side by side?
- Chart.js - Creating multiple charts on one page
- How to add multiple background color in line charts
- how to customize tool tip while mouse go over bars on Chart js bar chart
- Multiple charts not working chart.js
- How to use JSON data in creating a chart with chartjs?
- How can I load multiple Chartjs charts with different data on the same page?
- Chart.js creating multiple Charts in Angular in same Component
- How to draw multiple color bar in a bar chart using chart.js
- how to display multiple sum with chart js and laravel?
- charts js, doughnut chart not rendering tooptips correctly
- How to make bar chart cover multiple labels?
- How to show multiple datasets in line chart js
- How to map multiple charts with chart.js in react
- How to customize tooltip on mouse hover of a polar area chart of Angular Charts
- How to position chart details next to a chart responsive for multiple devices?
- How can i move a point through both x-axis and y-axis while the curve is not changed in a chart.js line graph?
- How to show Nested charts Radar chart within Doughnut Chart?
- Chart js update multiple charts
- How to add left padding for my charts done in ChartJs and my Google Map so it is not glued to the limit of the page on the left
- How can I display desired/particular chart in App.vue from Charts.vue which contains different charts in Vuejs
- How to print a chart rendered by code
- How to create multiple y-axis time series chart
More Query from same tag
- angular 5 reset chart js bar in same component
- GWT Chart.js implementation throws 'unable to get property 'insertBefore' of undefined or null reference
- Lift the bar up from the bottom in bar type chart
- Chart.js rotating x-axis text labels
- Load JSON to display data, using ng-repeat {ANGULAR.JS}
- Does this library have a way of showing a world map?
- Mapping data from JSON not parsing well
- How do i find area under the graph
- Horizontal stacked angular bar charts
- chartjs maintain points position, put image alongside with label
- ChartJS row size
- How to get the database data into ChartJS using codeigniter
- Why tooltip position absolute does not apply using js?
- chart.js Radar shows 0 when value is 12
- two xAxes horizontal bar chart Charts.js
- chart.js update() function not working correctly
- add value to Line chart.js
- Charts.js tooltip overlapping text on chart
- Chart.js color change of the data points
- Charts js only showing 2 data points on sparkline
- How do I use Chart.js and Bootstrap at same time? (various jQuery versions)
- How can I process json file and display some data in form of charts in django
- What's an efficient process for passing PHP arrays to to populate multiple ChartJS graphs?
- ChartJS: create linear x-axis on bar chart
- Chart.js Ionic 2 Angular2: Background color of bar graph not changing
- chartjs dataset attribute hidden from function
- How to hide more than one legend on Chartjs?
- How to call a typescript arrow function and a javascript function in the same event
- Ajax call to trigger a controller function
- ChartJs days of the week from numbers