score:4
Accepted answer
You extend the chart which you used and then write the labels using the helper methods
HTML
<canvas id="myChart" width="500" height="400"></canvas>
In the below JS, note that the parameter to calculateY
is the y value, while for calculateX
, it is label index
Chart.types.Line.extend({
name: "LineAlt",
draw: function(){
Chart.types.Line.prototype.draw.apply(this, arguments);
this.chart.ctx.textAlign = "center"
// y value and x index
this.chart.ctx.fillText("ZONE1", this.scale.calculateX(3.5), this.scale.calculateY(20.75))
this.chart.ctx.fillText("ZONE2", this.scale.calculateX(11.5), this.scale.calculateY(13))
this.chart.ctx.fillText("ZONE3", this.scale.calculateX(2), this.scale.calculateY(9.75))
this.chart.ctx.fillText("ZONE4", this.scale.calculateX(14.5), this.scale.calculateY(22.75))
}
});
var data = {
labels: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24],
datasets: [{
data: []
}]
};
var ctx = document.getElementById("myChart").getContext("2d");
var myBarChart = new Chart(ctx).LineAlt(data, {
scaleOverride: true,
scaleSteps: 16,
scaleStepWidth: 1,
scaleStartValue: 8,
animation: false
});
Fiddle - https://jsfiddle.net/bpfvvxpn/
Not sure how you created the line chart, so didn't add it to the fiddle
score:1
This is how I write inside a pie to create a gauge:
var start=0;
var stop=100;
var part=(stop-start)/3;
var pi_value=4.999;
var pi_name="مدت توقف";
var pi_unit="(روز)";
var pi_data=[30, 30, 20, 1, 9];
var inner={
backgroundColor: [
"rgba(0, 0, 0, 0)",
"rgba(0, 0, 0, 0)",
"rgba(0, 0, 0, 0)",
"rgba(0, 0, 0, 1)",
"rgba(0, 0, 0, 0)"
],
borderWidth: 0,
hoverBackgroundColor: [
"rgba(0, 0, 0, 0)",
"rgba(0, 0, 0, 0)",
"rgba(0, 0, 0, 0)",
"rgba(0, 0, 0, 1)",
"rgba(0, 0, 0, 0)"
],
hoverBorderWidth: 0
};
angular.module('PIR').controller("DoughnutCtrl", ['$scope', function ($scope) {
var originalDraw = Chart.controllers.doughnut.prototype.draw;
Chart.controllers.doughnut.prototype.draw = function(ease) {
if(this.index == 1){
let x = (this.chart.boxes[this.index].right)/2;
this.chart.chart.ctx.textAlign = "center";
this.chart.chart.ctx.fillText(pi_value, x, x*3/2);
this.chart.chart.ctx.fillText(start, 4*this.chart.boxes[this.index].left, x*3/2);
this.chart.chart.ctx.fillText(stop, this.chart.boxes[this.index].right-3*this.chart.boxes[this.index].left, x*3/2);
}
originalDraw.call(this, ease);
};
$scope.data = [pi_data, pi_data];
$scope.datasetOverride = [
{
backgroundColor: [
"rgb(255, 69, 96)",
"rgb(206, 148, 73)",
"rgb(153, 223, 89)",
"rgba(0, 0, 0, 1)",
"rgb(153, 223, 89)"
],
borderWidth: 0,
hoverBackgroundColor: [
"rgb(255, 69, 96)",
"rgb(206, 148, 73)",
"rgb(153, 223, 89)",
"rgba(0, 0, 0, 1)",
"rgb(153, 223, 89)"
],
hoverBorderWidth: 0,
},
inner
];
$scope.options = {
cutoutPercentage: 0,
rotation: -3.1415926535898,
circumference: 3.1415926535898,
legend: {
display: false
},
tooltips: {
enabled: false
},
title: {
display: true,
text: pi_name + ' ' + pi_unit,
fontSize: 14,
fontFamily: 'yekan',
position: 'bottom'
}
};
}]);
http://jtblin.github.io/angular-chart.js/
https://github.com/chartjs/Chart.js/issues/2874#issuecomment-273839993
Source: stackoverflow.com
Related Query
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- How to add text inside the doughnut chart using Chart.js?
- How to add text in centre of the doughnut chart using Chart.js?
- Chart.js - How to Add Text in the Middle of the Chart?
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- How to add text inside the doughnut chart using Chart.js AngularJS 2.0?
- How to add custom text inside the bar and how to reduce the step size in y axis in chart js( Bar chart )
- Chart.js - How to Add Text in the label of the Chart with JavaScript?
- Chart js. How to align text by the center of the tooltip?
- How to draw a needle on a custom donut chart and add datapoints to the needle?
- Vue Chart 3 - Doughnut Charts with Text in the Middle (Trouble registering a plugin)
- How to rotate the Label text in doughnut chart slice vertically in chart.js canvas, Angular 12?
- How add the sizes of the slices in the pie chart (at the top) in Chart.js?
- How to add space to the bottom of the chart in chartjs [angular]
- How to add labels on top of the chart bar with Chart.js 2
- Styling the middle text of Chart.js's doughnut chart
- How to add additional label in the middle of each bar using ChartJS
- How to add image inside the doughnut chart using chart.js?
- ChartJS - How to add Text between Pie Chart and Legend
- How do I add an image in the middle of Donut Chart?(Chart.js)
- how to see labels without losing middle text in doughnut chart
- How to add an on click event to my Line chart using Chart.js
- How do you hide the title of a chart tooltip?
- How to add an offset to a dataset in Chart js
- How to add second Y-axis for Bar and Line chart in Chart.js?
- chart js tooltip how to control the data that show
- How to add text at end of each line in charts.js
- How to add datas to chart js from javascript array itself?
- How to change the color of legend in chartjs and be able to add one more legend?
- How do I change the 'months' language displayed on the date axis in Chart JS?
More Query from same tag
- Chart js not showing negative y axis
- Dynamically populate array with Firebase Data Vue.js
- how to put a second pie chart right next to first pie chart inside the bootstrap card
- different colors for bar chart with chart.js
- How to make 2 bar in a certain section of chart
- Wkhtmltopdf does not render Chart.JS 2.5.0 graph
- Django and Chart.js: Line-Chart with multiple Datasets
- generate basic pie chart using chartjs
- Chartjs: How to offset ticks on radarchart?
- ChartJS - Display one set of data at a time
- How to rename properties in objects that are in an array. What is the right way to solve the task?
- There's a way to link bars to a file in a chart bar in chart.js?
- Chart.js change height on window resize while maintaining aspect ratio
- Chart.js not initiating
- How i can insert string data to diagrams in chart.js
- High and low points on chart getting cut off
- Chart.js tooltips callback function with pie charts
- How to change draw order by line property with chart.js
- Chart.js flickering
- chart js with angular2 loading dynamic data only after zoomin
- chart.js version 2.4.0 does not display bars for me
- Change Chartjs financial chart yaxis from left to right
- ChartJS + twig symfony
- How do remove the bottom scale on a Chart.js bar chart
- chart.js not working in browser with django. no error for template and static folder setting
- Chart.js 3.5: linear gradient doesn't apply properly when multiple bars in the same chart
- How do I add padding on the right of tooltip, but not the left in Chart.js?
- Chartjs not working with d3 from csv source
- using ajax populate dynamic piechart from chartjs
- Charts.js & Bootstrap Accordion