- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Google 图表时遇到了问题。我想要一个饼图,显示所有带有标签图例的值,包括低于 0.1% 的非常小的值。
假设我有以下数据:
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', 66],
['Sleep', 33.95],
['Eat', 0.05]
]);
(总匹配数最多为 100)
现在的问题是,在计算百分比时,Google Charts 会四舍五入这些值,导致 33.95 变成 34,因此 0.05 变成 0。
此处示例:https://jsfiddle.net/4qe7h21s/
有没有办法让图表引擎创建 2 位小数而不是 1 位小数的百分比?
最佳答案
因为没有选项可以更改百分比的格式或精度
首先,需要设置sliceVisibilityThreshold: 0.0001
所以 'Eat'
不会落入 'Other'
接下来,在数据中提供自定义格式的值{v: 66, f: '66.00%'}
将 pieSliceText
和 tooltip.text
设置为 'value'
因为 'Eat'
的切片很小,所以使用tooltip.trigger: '选择'
看下面的例子,切片显示正确的百分比
点击 'Eat'
的图例项以查看工具提示
google.charts.load('current', {
callback: function () {
new google.visualization.PieChart(document.getElementById('chart_div')).draw(
google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['Work', {v: 66, f: '66.00%'}],
['Sleep', {v: 33.95, f: '33.95%'}],
['Eat', {v: 0.05, f: '0.05%'}]
]),
{
height: 400,
legend: {
position: 'right'
},
pieSliceText: 'value',
sliceVisibilityThreshold: 0.0001,
title: 'My Daily Activities',
tooltip: {
showColorCode: true,
text: 'value',
trigger: 'selection'
},
width: 600
}
);
},
packages: ['corechart', 'table']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
关于javascript - 谷歌饼图 : rounding issue with 2 decimal percentages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433847/
为了使问题尽可能简单: 在 Excel 单元格 A1 中有一个数值:0.11 我想将单元格格式设置为百分比值,但不带 % 符号。我想要:11;不是 11% 我不是在问如何在常规 Excel 中执行此操
我正在努力提高我的 Spark Scala 技能,但我遇到了这个案例,我找不到操作方法,所以请指教! 我有原始数据,如下图所示: 我想计算计数列每个结果的百分比。例如。最后一个错误值为 64,64 在
在 firefox 中,我的结果符合预期。我正在尝试添加 width 和 padding 来组成完整尺寸。在 chrome 中这似乎不起作用, .tab-content { padding: 10px
我有一个字符串,其中可能出现 %[{variable}, percentage] 我想将其转换为 (({variable}*percentage)/100) 并将其替换在同一位置。最好的方法是什么?
前言 它看起来像是几个 stackoverflow 问题的重复,但我的情况(可能)有点独特。 我的情况 我有一本字典。 键是一个字符串,值是一个整数。 我希望 python 脚本随机选择 N 个键。
我喜欢在 Item 时计算“两行之间的变化百分比” 行的变化。 对于第一行项目,我可以放置一些文本或空白 (例如“跳过”或空白是可以的)因为没有比较前一行的相同 元素 df % group_by(
我无法理解百分比的意义。 在此站点中:https://developer.mozilla.org/en-US/docs/Web/CSS/top#Summary 它说:“引用包含 block 的高度”
我知道你可以在 Sass/Scss 中做一些简单的数学运算。但是有没有办法从百分比中减去像素?例如: $image-size: 200px; .bio { width: 100% - $ima
如果我想找到来自 12345 邮政编码区域的人数百分比,我会取具有该邮政编码的人数并将其与总人数相除……我在下面的示例查询中遗漏了什么?我不知道如何正确显示百分比。它只是一直说0%。 select (
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 7年前关闭。 Improve t
我对RPGLE了解不多。我正在尝试解决给我的这个小练习。我从来没有做过或见过使用小数的练习。我想获得 7 个值的百分比。所以,我想做如下计算。 例如在 RPGLE 中。 DTotal
我正在尝试使用正则表达式解析文本文件,将百分比作为字符串,并用百分比乘以用户提供的整数来替换结果。如果用户输入 400,则代码应返回“120 x 8、180 x 6 等” 尝试进行替换,但它用相同的字
我有一个有效的查询,但除了我已有的查询之外,我想为每个类别添加一个额外的列,即免费、减少、付费和认证免费,以及与学生总数相比的百分比。谁能帮我吗? select count(case
我需要获取百分比但不能使用 WHERE 子句,因为它是大型 SQL 查询的一部分。 我尝试这样做: select (count(sector='Rurality'))/(count(sector))*
是否可以对 Elastic Search 进行查询,以返回分数占最大分数的百分比?到目前为止,它返回的值如 "_score": 0.00786336, 以及最大分数如 max_score": 0.13
如果我以百分比形式给出“from”值,以像素为单位给出“to”值,则“弹跳动画不会按预期工作。 请检查这里的代码:http://jsfiddle.net/xJ4xy/ 解决方案是什么? (我尽量不使用
我正在使用百分比来缩放我网站上图库中的缩略图,但我无法使用 object-fit: cover 来处理它们。我正在尝试使用 object-fit,这样我就可以让缩略图实际上是方形的,而不是图像本身具有
我有一个包含 2 个“配对”整数数组 newNumerator[ ] 和 newDenominator[ ] 的程序,它们都有 9 个整数。我编写了一个按升序对它们进行排序的函数,但是我不确定它是否有
遗憾的是,我试过目视它,但没有结果。 我想做的是根据百分比进行变亮/变暗混合:如果百分比 0,则执行“变亮(@color,@light)”。 像这样: ._changeColor(@color, @
我在一个使用标准网格系统的响应式网站上工作,所以我的 div 不能有固定的高度。话虽如此,我已经设置了一个 fiddle 文件来模拟我的问题。出于美观原因,我在桌面上的最小高度为 50px,并将行高也
我是一名优秀的程序员,十分优秀!