Javscript Plotly错误:'像重新绘制一样进行绘图调用,但此容器尚无绘图”

问题描述 投票:0回答:1

我正在尝试根据用户在下拉列表上的选择来绘制其他饼图。 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)
    }) 

对于每个“如果”条件,console.log将显示正确的“ proj_name”和“ proj_hrs”数组。但是在绘图中,错误显示为“正在调用Plotly.plot,就像重绘一样,但此容器尚无绘图。”

请帮助!深表感谢!

javascript html d3.js plotly
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.