【问题标题】:Adding an image with C3.js使用 C3.js 添加图像
【发布时间】:2017-06-10 09:21:48
【问题描述】:

我正在尝试将图像添加到用 C3.js 制作的图表中

我需要让图像位于图表的中心,并且我在一页上有 6 个这样的图表。

我想用图像替换传输等的文本。

这是我用来生成图表的代码。

    var transport = c3.generate({

    data: {
        columns: [
            ['Labour', labourLikes],
            ['Greens', greensLikes],
            ['National', nationalLikes],
            ['United Future', unitedfutureLikes],
            ['ACT', actLikes],
            ['NZ First', nzfirstLikes],
        ],
        type: 'donut',
        colors: {
            Labour: '#D82C20',
            Greens: '#00C760',
            National: '#0B6FAA',
            'United Future': '#40003F',
            ACT: '#FFDE00',
            'NZ First': '#000',
        },
        onclick: function (d, i) { console.log("onclick", d, i); },
        onmouseover: function (d, i) { console.log("onmouseover", d, i); },
        onmouseout: function (d, i) { console.log("onmouseout", d, i); }
    },
    donut: {
        title: "Education"
    },
    legend: {
        show: false
    },
    bindto: '#education'

});

非常感谢任何帮助。

【问题讨论】:

    标签: javascript d3.js c3.js


    【解决方案1】:

    您可以将图像插入圆环图的中心节点 - .c3-chart-arcs

    oninit: function() {
        var element = this.selectChart[0][0]
        var center = d3
          .select(element)
          .select('.c3-chart-arcs')
          .insert('image',':first-child')
          .attr('x', -75)
          .attr('y', -75)
          .attr('width', 150)
          .attr('height', 150)
          .attr('xlink:href', 'http://pngimages.net/sites/default/files/small-png-image-20665.png')
    }
    

    this fiddle

    【讨论】:

      猜你喜欢
      • 2018-04-08
      • 2018-03-02
      • 1970-01-01
      • 2015-03-30
      • 2015-12-04
      • 1970-01-01
      • 2014-04-17
      • 2016-08-30
      • 2015-09-10
      相关资源
      最近更新 更多