javascript - 圆环图内的图像 - AmCharts

标签 javascript amcharts donut-chart

我正在尝试将图像放入饼图的内半径内。所以它看起来像这样:

enter image description here

我发现的最接近的是 title and subtitle inside 。但它会在 de svg 中生成一个文本标记,因此我找不到显示图像的方法。

AmCharts.makeChart("chartdiv", {
"type": "pie",
"theme": "none",
"allLabels": [{
    "text": "This is chart title",
    "align": "center",
    "bold": true,
    "y": 220
},{
    "text": "Ans here's the subtitle as well",
    "align": "center",
    "bold": false,
    "y": 250
}],
"dataProvider": [{
    "title": "New",
    "value": 4852
}, {
    "title": "Returning",
    "value": 9899
}],
"titleField": "title",
"valueField": "value",
"labelRadius": -130,
"radius": "42%",
"innerRadius": "60%",
"labelText": ""
});

谢谢!

最佳答案

从技术上讲,不可能在 amCharts 饼图中添加图像作为标签。

但是,您可以通过添加该图像作为图表容器的背景来轻松解决这个问题。即:

#chartdiv {
  width: 210px;
  height: 210px;
  background: transparent url(logo.png) no-repeat center 70px;
}

这是应用上述内容的图表:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "pie",
  "dataProvider": [{
    "slice": "First",
    "value": 34
  }, {
    "slice": "Second",
    "value": 66
  }],
  "valueField": "value",
  "titleField": "slice",
  "labelsEnabled": false,
  "pullOutRadius": 0,
  "innerRadius": 60,
  "allLabels": [{
    "text": "34%",
    "color": "#f40000",
    "size": 20,
    "align": "center",
    "y": "55%"
  }]
});
#chartdiv {
  width: 210px;
  height: 210px;
  margin: 0 auto;
  background: transparent url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-160/so1.png) no-repeat center 70px;
}
<script src="http://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="http://www.amcharts.com/lib/3/pie.js"></script>
<div id="chartdiv"></div>

关于javascript - 圆环图内的图像 - AmCharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33021559/

相关文章:

javascript - 在超链接的点击事件上调用javascript函数

javascript - 检索行时出现钛错误

javascript - AmCharts 使用 validateData() 从 dataProvider 中删除列不起作用

javascript - 如何从特定选定行的事件发送者数据中获取模型数据?

javascript - 删除 jQuery.trim() 忽略的文本区域中的空白

javascript - amChart 列文本自动旋转

javascript - 为什么 am 图表导出顶部的饼图/图例黑色?

安卓 donut chart

javascript - Highcharts.js : get specific value from data to tooltip