javascript - Flot Chart API - 图表外的图例
问题描述
我想用flot chart api写饼图
我想像上面这样画,但我的图表状态是
与上图相同,所以我想删除图表上的标题,但保留第一张图片的百分比信息。
附上我的图表选项:
// myChartOption
var options = {
series: {
pie: {
show: true,
label: {
show:true,
radius: 0.8,
formatter: function (label, series) {
return '<div style="border:1px solid grey;font-size:8pt;text-align:center;padding:5px;color:white;">' +
label + ' : ' +
Math.round(series.percent) +
'%</div>';
},
background: {
opacity: 0.8,
color: '#000'
}
}
}
/*
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 2/3,
formatter: labelFormatter,
}
}
*/
},
legend: {
container:$("#" + legendContainer),
show: true
}
};
解决方案
首先,欢迎来到 stackoverflow 社区,祝您编码愉快。请将您的代码添加到问题中,它使其更具可读性并帮助人们更好地理解问题。
您应该在设置中添加如下内容:
var legendContainer = document.getElementById('#my-legend-container'); // your container of the legends
legend: {
show: true,
position: "ne", // north east, please refer to documentation for "ne" or "nw" or "se" or "sw"
container: legendContainer, // jQuery object/DOM element/jQuery expression
}
推荐阅读
- matrix - 使用 Julia 将未格式化的 FORTRAN 文件读入多维数组
- reactjs - 单击卡片时如何路由到具有特定卡片详细信息的页面?
- javascript - 根据范围返回数组中的对象
- c++ - 为什么必须在线程销毁之前调用 join() 或 detach() ?
- c# - 未找到命令 dotnet ef
- arrays - 在二进制数组中查找集群组
- python - 尝试使用烧瓶和 apache 运行网站时出现 404 not found 错误
- r - 从数据框中创建一个列表:A 列是变量,B 列与 C 列中的值相关联
- c++ - 是否强制转换为仅包含 char[] 并从该数组中读取的结构定义良好?
- reactjs - 如何强制地将 prop 分配给 React 组件?