gpt4 book ai didi

javascript - Plotly JavaScript - donut chart - Hoverinfo,尝试使用数组添加自定义定义 - 我的代码的小问题

转载 作者:行者123 更新时间:2023-12-04 16:12:36 25 4
gpt4 key购买 nike

我有一个 Plotly.JS 圆环图,我希望用户能够将鼠标悬停在数据上并查看除了标签和数据之外的每种医疗保健类型的定义。例如,当他们将鼠标悬停在 Specialty Care 上时,我希望它看起来像这样:
专科护理
42.9%
专科护理定义

我想我可以添加一组定义(参见“desc:”)并添加它hoverinfo,但要么你不能,要么我做错了。我的问题是我如何让它工作,这样我才能让它看起来像上面的粗体?
这是我的代码笔:https://codepen.io/tenebris_silentio/pen/OJNJxGX

   <!DOCTYPE html>
<html lang="en">
<div id='myDiv'>
<script>

var ultimateColors = [
['rgb(0, 25, 51)', 'rgb(0, 76, 153)', 'rgb(51, 153, 255)', 'rgb(153, 204, 255)', 'rgb(51, 51, 255)', 'rgb(204, 255, 255)']
];

var data = [{
values: [4, 21, 8, 1, 1, 14],
labels: ['Primary Care', 'Specialty Care', 'Mental Health', 'Inpatient/Acute Care', 'Long-term Care', 'General Care/Not Specified'],
desc: ['Primary Care Definition', 'Specialty Care Definition', 'Mental Health Definition', 'Inpatient/Acute Care Definition', 'Long-term Care Definition', 'General Care/Not Specified Definition'],
domain: {column: 0},
name: 'Sources',
marker: {
colors: ultimateColors[0]
},
hoverinfo: 'label+percent+desc',

hole: .4,
type: 'pie'
}];

var layout = {
title: 'Access Projects by Care Type' + '<br>' + 'N = 49',
annotations: [
{
font: {
size: 17
},
showarrow: false,
text: '',
x: 0.5,
y: 0.5
},


],
height: 650,
width: 800,
showlegend: true,
grid: {rows: 1, columns: 1}
};

Plotly.newPlot('myDiv', data, layout);
</script>

最佳答案

天啊,当答案如此接近以至于可能会打到你的脸时,你不讨厌吗?我需要做的就是添加一个文本数组并引用它。我只需要修复 var 数据中的部分。特别是,我添加了“text:”部分和“textinfo”(从出现在 donut 中取出新添加的定义)。然后我只是添加了对hoverinfo的文本引用。就是这样!

var data = [{
values: [4, 21, 8, 1, 1, 14],
labels: ['Primary Care', 'Specialty Care', 'Mental Health', 'Inpatient/Acute Care',
'Long-term Care', 'General Care/Not Specified'],
desc: ['Primary Care Definition', 'Specialty Care Definition', 'Mental Health
Definition', 'Inpatient/Acute Care Definition', 'Long-term Care Definition', 'General
Care/Not Specified Definition'],
text: ['The project is focused on primary care.', 'The project is focused on specialty
care.', 'The project is focused on mental health', 'The project is focused on
inpatient/acute care', 'The project is focused on long-term care', 'The type of care
is not indicated or is not specific to one type'],
textinfo: 'none',
domain: {column: 0},
name: 'Sources',
marker: {
colors: ultimateColors[0]
},
hoverinfo: 'label+percent+desc+text',

hole: .4,
type: 'pie'
}];

关于javascript - Plotly JavaScript - donut chart - Hoverinfo,尝试使用数组添加自定义定义 - 我的代码的小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63265445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com