gpt4 book ai didi

jQuery flot 饼图标签格式

转载 作者:行者123 更新时间:2023-11-28 09:35:41 25 4
gpt4 key购买 nike

我正在尝试格式化我的查询 flot 饼图标签和图例。

这是我到目前为止创建的:

enter image description here

这就是我要创建的(我使用 photoshop 完成的):

enter image description here

如您所见,我正在努力将百分比和值包含在饼图中(看到百分比是粗体而值不是),并且垂直居中对齐图例。

代码如下:

(function () {

var data = [
{ label: "Sales & Marketing", data: 9545, color: "#62A83B"},
{ label: "Research & Development", data: 16410, color: "#2897CB"},
{ label: "General & Administration", data: 4670, color: "#DEAB34"}
];

$(document).ready(function () {
$.plot($("#expenses-chart"), data, {
series: {
pie: {
show: true
}
},
legend: {
show: true,
labelFormatter: function(label, series) {
var percent= Math.round(series.percent);
var number= series.data[0][1]; //kinda weird, but this is what it takes
return('&nbsp;<b>'+label+'</b>:&nbsp;'+ percent + '%');
}
}
});
});

})();

有什么想法吗?谢谢!

最佳答案

您的第一个问题主要是关于标记和 CSS 的问题。我会将图例放在它自己的 div 和 style that to vertically 中对齐它。

<style>
#wrapper {
display: inline-flex;
}
#legend {
margin: auto 5px;
}
#expenses-chart{
float: left;
width: 300px;
height: 300px;
}
.pieLabel{
color: #fff;
}
</style>

<div id="wrapper">
<div id="expenses-chart"></div>
<div id="legend"></div>
</div>

对于饼图内的标签,您需要为标签指定自定义格式化程序:

$.plot($("#expenses-chart"), data, {
series: {
pie: {
show: true,
radius: 150,
label: {
show: true,
radius: 0.5, // place in middle of pie slice
formatter: function(label, series){
var percent = Math.round(series.percent);
var number = series.data[0][2]; // this is the y value of the first point
return ('&nbsp;<b>' + percent + '%</b><br/>$' + number); // custom format
}
}
}
},
legend: {
show: true,
container: $("#legend")
}
}

将它们放在一起产生(例如 here ):

enter image description here

关于jQuery flot 饼图标签格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27883284/

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