如何解决使用D3在饼图中添加数据
我有一个使用d3的应用程序。
mongorestore ./dump_prod --gzip --drop --nsExclude 'MyDatabase.IdentityServerClients'
我想在数字附近的图表中添加其他数据,例如:
- 25个苹果
- 59樱桃
- 77辆车
我现在拥有的代码is here
问题:如何在图表中添加类似于我上面所述的文本附近的数字?
解决方法
假设您可以自己更改#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window,int width,int height);
void processInput(GLFWwindow* window);
int main() {
// Initialize GLFW
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,6);
glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
// Create GLFW Window
GLFWwindow* window = glfwCreateWindow(800,600,"Golden Retriever",NULL,NULL);
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window,framebuffer_size_callback);
// Initialize GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// Render Loop
while (!glfwWindowShouldClose(window)) {
processInput(window);
glClearColor(0.2f,0.3f,1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window,int height) {
glViewport(0,width,height);
}
void processInput(GLFWwindow* window) {
if (glfwGetKey(window,GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window,true);
}
,我将执行以下操作:
- 更改
PieGraph.js
以接受带有Arc
和value
的数据
piegraph.js
label
- 更改您传递给
const Arc = ({ data,index,createArc,colors,format }) => ( <g key={index} className="arc"> <path className="arc" d={createArc(data)} fill={colors(index)} /> <text transform={`translate(${createArc.centroid(data)})`} textAnchor="middle" fill="white" fontSize="10" > // Here is the change {data.format !== undefined ? data.format : format(data.value)} </text> </g> );
的数据
index.js
Pie
现在,第一个带有标签“ 25 apples”,第二个带有标签“ ”,第三个带有标签“ const [data,setData] = useState([
{
value: 25,label: '25 apples',},{
value: 59,label: '',{
value: 77
}
]);
”(
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。