Jquery饼图在每个切片上添加背景图像

ct2axkht  于 2023-03-17  发布在  jQuery
关注(0)|答案(1)|浏览(117)

我想在Piechart的每个切片上放一个背景图片。我应该把这个代码的背景图片放在哪里?

window.onload = function() {

  var mychart = {
    animationEnabled: true,
    legend:{
      horizontalAlign: "top",
      verticalAlign: "top",
      fontColor: "#fff"
    },
    data: [{
      type: "pie",
      showInLegend: true,
      explodeOnClick: false,
      toolTipContent: "<b>{name}</b>",
      indexLabel: "{name}",
      legendText: "{name}",
      indexLabelPlacement: "inside",
      indexLabelFontColor: "#fff",
      indexLabelFontSize: 12,
      indexLabelMaxWidth:100 ,
      dataPoints: [
        { y: 10, name: "BUSINESS BRANDING", link: "https://yourcompanygo.com/business-admin/", color: "#36A2EB"  },
        { y: 10, name: "BUSINESS ASSETS", link: "https://yourcompanygo.com", color: "#FFCE56"},
        { y: 10, name: "BUSINESS FORMATION", link: "https://yourcompanygo.com",  color: "#c0504e"},
        { y: 10, name: "BUSINESS ADMINISTRATIVE", link: "https://yourcompanygo.com/get-started/", color: "#FF6384" }
      ],
      click: function(e) {
        if (e.dataPoint.link) {
          window.open(e.dataPoint.link, "_blank");
        }
      }
    }],
    backgroundColor: "transparent"
  };

  var chart = new CanvasJS.Chart("chartContainer", mychart);

  chart.options.data[0].toolTipContent = "<b>{name}</b>";
  chart.options.data[0].dataPoints.forEach(function (d) {
    d.mouseover = function () {
      chart.options.data[0].dataPoints.forEach(function (p) {
        p.color = (p.name === d.name) ? "red" : p.color;
      });
      chart.render();
    };
    d.mouseout = function () {
      chart.options.data[0].dataPoints.forEach(function (p) {
        p.color = p.color.replace("red", "").trim();
      });
      chart.render();
    };
  });

  chart.render();

};

我已经试过indexLabelBackgroundColor:“url(https://example.com/image1.jpg)”在数据点上改变颜色到图象.看参考url在这里https://canvasjs.com/jquery-charts/pie-chart-index-data-label-inside/

ecbunoof

ecbunoof1#

经过调查(阅读插件文档),我看到这是不可能把图像作为背景的每一个切片的piechart。
你应该提出一个产品建议来添加它,自己添加它或者找到另一个能够做到这一点的插件。
他们有论坛和快速聊天,在那里你可以问他们关于这一点。

相关问题