如何在圆环图中呈现文本,我使用的是ChartJs。
发布于 2014-03-03 14:41:04
您必须像这样修改代码:在chart.Doughnut.defaults
中
labelFontFamily : "Arial",
labelFontStyle : "normal",
labelFontSize : 24,
labelFontColor : "#666"
然后在函数drawPieSegments
中
ctx.fillText(data[0].value + "%", width/2 - 20, width/2, 200);
看看这个拉动:https://github.com/nnnick/Chart.js/pull/35
下面是一个实现相同功能的fiddle http://jsfiddle.net/mayankcpdixit/6xV78/。
发布于 2014-08-07 21:34:51
我会避免修改chart.js代码来实现这一点,因为使用常规的CSS和HTML很容易。这是我的解决方案:
HTML:
<canvas id="productChart1" width="170"></canvas>
<div class="donut-inner">
<h5>47 / 60 st</h5>
<span>(30 / 25 st)</span>
</div>
CSS:
.donut-inner {
margin-top: -100px;
margin-bottom: 100px;
}
.donut-inner h5 {
margin-bottom: 5px;
margin-top: 0;
}
.donut-inner span {
font-size: 12px;
}
输出如下所示:
发布于 2014-08-21 19:20:01
这对我来说也是有效的……
<div style="width: 100px; height: 100px; float: left; position: relative;">
<div
style="width: 100%; height: 40px; position: absolute; top: 50%; left: 0; margin-top: -20px; line-height:19px; text-align: center; z-index: 999999999999999">
99%<Br />
Total
</div>
<canvas id="chart-area" width="100" height="100" />
</div>
https://stackoverflow.com/questions/20966817
复制相似问题