How to Create Doughnut Chart with Labels Outside with Connecting Line in Chart js

How to Create Doughnut Chart with Labels Outside with Connecting Line in Chart js

Chart JS

3 года назад

26,335 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@naminjaepocaeramelhor
@naminjaepocaeramelhor - 14.12.2021 23:28

Great video friend, I would like you to explain in video how to make a chart that automatically updates with data in json...thanks great video

Ответить
@ЗамирЮсупов-щ9к
@ЗамирЮсупов-щ9к - 23.12.2021 12:13

WOW! Very appreciate! You helped me and safe my time!

Ответить
@gary7135
@gary7135 - 25.01.2022 04:09

does it work with react typescript?

Ответить
@samlokta447
@samlokta447 - 07.02.2022 14:42

How can we achieve same in piechart. Thanks

Ответить
@ivankosheliev7227
@ivankosheliev7227 - 07.02.2022 18:19

Hey, how to create multiple labels that not depends from numbers of data. For example like speedometer? is it possible to arrange the elements in that way?

Ответить
@kshitijkhot1401
@kshitijkhot1401 - 20.02.2022 15:46

nice explanation , THANKS A LOT. 🙃🙃.

Ответить
@adenugaayoade1934
@adenugaayoade1934 - 27.02.2022 13:48

Thank you for this❤

Ответить
@CryptoKosh
@CryptoKosh - 07.03.2022 11:34

Really great tutorial ✅✅

Ответить
@juancarloscarrasquillapela4756
@juancarloscarrasquillapela4756 - 01.04.2022 16:32

how can I do this with chart js (2.9.3) - ng2 chart(2.3.2)?

Ответить
@klaudiapaluch5868
@klaudiapaluch5868 - 29.04.2022 23:38

THANK YOU !!!

Ответить
@sanjeebgochhayat6911
@sanjeebgochhayat6911 - 18.05.2022 12:17

i do not get the data while console.log(chart.data.datasets)...anyone have the solution

Ответить
@mauriciosanchez813
@mauriciosanchez813 - 24.06.2022 03:01

Nice Video and really great content. Question, how can I make the same thing but with the datalabels inside each slice in piechart for example?, like when you have percentage datalabels inside each slice. Thanks!

Ответить
@kasperskov1337
@kasperskov1337 - 05.07.2022 13:27

So one thing I can't figure out is why your x and y tooltip coordinates aren't influenced by your chart padding. Or maybe it really is. If you were to set the padding to chart width / 2, wouldn't all your calculations be off by padding x value? The tooltip coordinates are calculated from canvas edges not the chart edges.

Ответить
@julianascandolafrossard226
@julianascandolafrossard226 - 05.08.2022 19:41

Thank you for the video, but i wanna know how to Create PIE Chart with Labels Outside with Connecting line

Ответить
@Shriio
@Shriio - 23.08.2022 20:07

Holy shit dude, thanks so much.

Ответить
@sahilgrwl15
@sahilgrwl15 - 06.09.2022 15:20

Is it possible to do the same to chartjs 2.9.4?

Ответить
@prasadgore2166
@prasadgore2166 - 09.09.2022 19:34

When there is small and very large datasets labels overlapp, what is the solution for that

Ответить
@indofiz1077
@indofiz1077 - 22.09.2022 21:19

Well, when i use pie, the tooltip far from the side, how can i change the position of tooltip (Side Pie)

Ответить
@chineduotutu3723
@chineduotutu3723 - 04.10.2022 11:43

Nice video man!!! I want to ask how can I get the lines to start from the centre but on top of each slice, right now it starts at the centre but from inside each slice, thanks!!

Ответить
@aexelm
@aexelm - 07.10.2022 02:23

Awesome, wonderful ... no words!!. Excelent explained!

Ответить
@bhumikashah7461
@bhumikashah7461 - 18.10.2022 13:52

Thank you for the video. It's of great help.
I have a question though - when the slices of the Chart are small, the labels are overlapping with each other. How to fix this? Kindly respond.

Ответить
@riteshsingh-xi3hv
@riteshsingh-xi3hv - 24.10.2022 09:31

Thank you very much the way you explain step by step and very simple to understand.
I am facing issue in this. When the data points have big difference like: data: [3, 2, 1, 100, 105] then labels are overlapping.
Please provide some solution.
Thanks

Ответить
@kslangdon2102
@kslangdon2102 - 09.12.2022 08:23

Excellent tutorial! thanks. But how do I show the data in percentage instead of the label?

Ответить
@afsarali9
@afsarali9 - 22.12.2022 14:00

Thank you for the video. It's great help.
I have a question though - when the slices of the Chart are small, the labels are overlapping with each other. How to fix this?

Ответить
@ankanbrahmachary6581
@ankanbrahmachary6581 - 26.12.2022 13:36

Hey... Could you please help me on how to use this technique with ng2 charts in angular 15? Is there any work around for that?

Ответить
@arianquechua5625
@arianquechua5625 - 07.02.2023 18:46

Would you mind to publish this plugin as an npm package?

Ответить
@Seven77tw
@Seven77tw - 20.02.2023 09:45

life saver

Ответить
@oldold2027
@oldold2027 - 02.03.2023 05:58

In my dashboard I need multiple charts in the same page with different values. How can I do it?

Ответить
@fish_the_robot
@fish_the_robot - 10.05.2023 23:50

Thank you very much learned much, thanks for explaining it so well and taking the time to make these videos. I Appreciate it, thx.

Ответить
@mohanavamsikalangi2549
@mohanavamsikalangi2549 - 17.05.2023 17:21

HI this was a nice way and I have implemented this and worked but in my page I am destroying the chart and rebuilding again . When this happens the font of the text shown is becoming bolder . How to solve this ??

Ответить
@bagussonarangga7283
@bagussonarangga7283 - 31.05.2023 06:06

thankyou

Ответить
@alessandrop.5131
@alessandrop.5131 - 08.06.2023 11:30

Nice.
I have a little issue, in my doughnut chart.
I have a lot of data and little slices, the label outside overlaps each other, how can avoid overlapping?

Ответить
@hathuan7457
@hathuan7457 - 27.06.2023 04:26

why when I select a legend to hide the dataset (checked that the condition hiddenIndices is satisfied to hide the line and text), when I turn the legend back on, it doesn't show up again?

Ответить
@IliaBroudno
@IliaBroudno - 24.08.2023 03:43

Can you post a link to your code please?

Ответить
@iganic7574
@iganic7574 - 20.04.2024 21:11

please provide me final code it look complicated i will just copy past it.

Ответить
@Emiwryy
@Emiwryy - 30.05.2024 00:44

You made me so happy with this video I literally cried tears of joy when I finally understood the gimmick behind the idea, thank you SO much, I do mean this

Ответить
@anilkumar-it5qk
@anilkumar-it5qk - 02.06.2024 22:13

CODE

const doughnutLabelsLine = {
id: "doughnutLabelsLine",

afterDraw(chart, args, options) {
const {
ctx,
chartArea: { top, bottom, left, right, width, height },
} = chart;

chart.data.datasets.forEach((dataset, datasetIndex) => {
chart
.getDatasetMeta(datasetIndex)
.data.forEach((datapoint, dataPointIndex) => {
const { x, y } = datapoint.tooltipPosition();
console.log(x);

// draw line
const halfwidth = width / 2;
const halfheight = height / 2;

const xLine = x >= halfwidth ? x + 15 : x - 15;
const yLine = y >= halfheight ? y + 15 : y - 15;
const extraLine = x >= halfwidth ? 15 : -15;

// line
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(xLine, yLine);
ctx.lineTo(xLine + extraLine, yLine);

ctx.strokeStyle = dataset.borderColor[dataPointIndex];
ctx.stroke();

// text
const textWidth = ctx.measureText(
chart.data.labels[dataPointIndex]
).width;
console.log(textWidth);

ctx.font = "12px Arial";

// control the position
const textXPosition = x >= halfwidth ? "left" : "right";
const plusFivePx = x >= halfwidth ? 5 : -5;

ctx.textAlign = textXPosition;
ctx.textBaseline = "middle";
ctx.fillStyle = dataset.borderColor[dataPointIndex];

ctx.fillText(
chart.data.labels[dataPointIndex],
xLine + extraLine + plusFivePx,
yLine
);
});
});
},
};

Ответить
@shubhamdiwadkar1442
@shubhamdiwadkar1442 - 05.09.2024 06:45

Thankyou for making this video, their is another thing to the same I need multiple labels in place of single label.

Can this also be configured in the same

Ответить
@nourbagouri
@nourbagouri - 08.12.2024 02:24

This has been super helpful, thank you. I'm wondering how we could apply this with longer labels, since they get cut off for being too long.
Edit: chart.options.maintainAspectRatio = false; did that for me :)

Ответить
@IroshanaRavishan
@IroshanaRavishan - 14.12.2024 19:55

This is really nice. The only video I found regarding tcollecting the data labels with the chart. Thank you so much. It works as expected

Ответить