gpt4 book ai didi

javascript - Javascript Plotly 错误 : 'calling plotly as if redrawing but this container doesn' t have a plot yet"

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

我正在尝试根据用户在下拉列表中的选择绘制不同的饼图。 console.log 正在输出正确的信息,但绘图区域会抛出错误:“调用 Plotly.plot 就像重绘一样,但此容器还没有绘图。”下面是我的代码(抱歉有点长),但我会尝试总结我面临的问题。

function nameChanged(){
var selected_month = d3.select('#selMonth').property('value');
var selected_researcher = d3.select('#selName').property('value');
var proj_name = []
var proj_hrs = []
d3.json('mar_byweek.json').then((data)=>{

if ((selected_month ==="march")&& (selected_researcher ==='amber')
//some other code here to do something, which works //
d3.json('marAmber_byprod.json').then((data) =>{
proj_name = data.map(row => row.Product);
proj_hrs = data.map(row =>row.Total);
console.log(proj_name, proj_hrs)
})};

if ((selected_month ==="march")&& (selected_researcher ==='gwen')) {
//some other code here to do something, which works//

d3.json('marGwen_byprod.json').then((data) =>{
proj_name = data.map(row => row.Product);
proj_hrs = data.map(row =>row.Total);
console.log(proj_name, proj_hrs)
})};

var trace_project = {
labels: [proj_name],
values: [proj_hrs],
type: "pie",
}
Plotly.newPlot('month_pie', trace_project)
})

对于每个“if”条件,console.log 显示正确的“proj_name”和“proj_hrs”数组。但在绘图时,错误显示“调用 Plotly.plot 就像重绘一样,但此容器还没有绘图。”

求助!深表谢意!!!

最佳答案

trace_project 放入一个数组中:[trace_project]

关于javascript - Javascript Plotly 错误 : 'calling plotly as if redrawing but this container doesn' t have a plot yet",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61022216/

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