简体   繁体   English

Morris.js甜甜圈标签

[英]Morris.js Donut labels

I'm having an extremely frustrating time trying to move the data text labels from this donut chart to be outside of the center. 我在尝试将数据文本标签从该甜甜圈图移到中心之外时感到非常沮丧。 http://jsbin.com/ukaxod/144/embed?javascript,live the xpos and ypos are generated dynamically, and I can't seem to overwrite them with CSS and I can't find what is setting them in JS. http://jsbin.com/ukaxod/144/embed?javascript ,实时生成xpos和ypos是动态生成的,我似乎无法用CSS覆盖它们,也无法找到在JS中对其进行设置的内容。 A little help would be very appreciated. 一点帮助将不胜感激。 thanks 谢谢

The label in the center is placed there by design and cannot be simply changed. 中心的标签是根据设计放置的,不能简单地更改。

If you look at the source code you can find these lines: 如果您查看源代码,则可以找到以下几行:

Donut.prototype.redraw = function() {
    // ...
    cx = this.el.width() / 2;
    cy = this.el.height() / 2;
    // ...
    this.text1 = this.drawEmptyDonutLabel(cx, cy - 10, this.options.labelColor, 15, 800);
    this.text2 = this.drawEmptyDonutLabel(cx, cy + 10, this.options.labelColor, 14);
    // ...
}

It calculates cx/cy so that they point to the center of the chart, and generates 2 labels (for text and value). 它计算cx / cy使其指向图表的中心,并生成2个标签(用于文本和值)。 You can change the source code, or you can try to find the corresponding text tag in the svg code and change its x and y properties. 您可以更改源代码,也可以尝试在svg代码中找到相应的text标签并更改其x和y属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM