gpt4 book ai didi

javascript - 如何在dimple js中创建气泡饼图

转载 作者:行者123 更新时间:2023-12-03 05:56:24 26 4
gpt4 key购买 nike

我是酒窝新手,在创建气泡饼图时遇到问题。我希望每个气泡也是一个显示区域百分比的饼图。我尝试使用 myChart.addSeries(["North America", "Latin America"], dimple.plot.pie); 插入饼图但没有成功。有什么建议么?谢谢!

function draw(data) {
/*
D3.js setup code
*/
"use strict";
var margin = 75,
width = 1400 - margin,
height = 600 - margin;

var svg = d3.select("body")
.append("svg")
.attr("width", width + margin)
.attr("height", height + margin)
.append('g')
.attr('class','chart');
/*
Dimple.js Chart construction code
*/
var myChart = new dimple.chart(svg, data);
myChart.addCategoryAxis("x", "Target Date");
myChart.addCategoryAxis("y", "Target Reduction");
myChart.addMeasureAxis("z", "Number of Cities");

myChart.addSeries(
["Cities",
"North America",
"Latin America"],
dimple.plot.bubble);

//myChart.addSeries(["North America", "Latin America"], dimple.plot.pie);

myChart.addLegend(180, 10, 360, 20, "right");
myChart.draw();
/*
Add horizontal line at 50%
*/
svg.append("line")
.attr("x1", margin+65)
.attr("x2", 1250)
.attr("y1", 325)
.attr("y2", 325)
.style("stroke", "red")
.style("stroke-dasharray", "3");
/*
Add horizontal line at 85%
*/
svg.append("line")
.attr("x1", margin+65)
.attr("x2", 1250)
.attr("y1", 180)
.attr("y2", 180)
.style("stroke", "red")
.style("stroke-dasharray", "3");
/*
Add chrt title
*/
svg.append("text")
.attr("x", myChart._xPixels() + myChart._widthPixels() / 2)
.attr("y", myChart._yPixels() - 20)
.style("text-anchor", "middle")
.style("font-family", "sans-serif")
.style("font-weight", "bold")
.style("font-size", "20px")
.text("Emissions Targets set by CDP Cities");


};

d3.csv("data.csv", draw);
<style></style>
<body></body>  

最佳答案

这引起了我的兴趣,因此我使用 RGraph 创建了一个演示。这不是一个微不足道的代码量 - 但它确实完成了这项工作,并且可以在下载中使用

demos/scatter-bubble-pie-chart.html

您可以在这里下载:

https://www.rgraph.net/download.html#stable

关于javascript - 如何在dimple js中创建气泡饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39909218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com