Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 创建烛台图并使用getImage plotly_Javascript_Node.js_Plotly - Fatal编程技术网

Javascript 创建烛台图并使用getImage plotly

Javascript 创建烛台图并使用getImage plotly,javascript,node.js,plotly,Javascript,Node.js,Plotly,我使用了plotly.plot,它将图形发送到我的帐户。你能在烛台图上使用getImage吗?我发出了一个getImage请求,返回了错误响应状态代码500。我是否遗漏了一些需要添加的必需变量 这是我的密码: var title = `${data.name} from ${x[x.length - 1]} to ${x[0]}`; //picture requirements var imgOpts = { format: 'png', width: 1000,

我使用了plotly.plot,它将图形发送到我的帐户。你能在烛台图上使用getImage吗?我发出了一个getImage请求,返回了错误响应状态代码500。我是否遗漏了一些需要添加的必需变量

这是我的密码:

var title = `${data.name} from ${x[x.length - 1]} to ${x[0]}`;

//picture requirements
var imgOpts = {
     format: 'png',
     width: 1000,
     height: 500
};

var open = [], high = [], low = [], close = [];
//code that fills variables

var layout = {
        margin: {l: 50, r: 20, t: 50, b: 0},
        showlegend: false,
        xaxis: {
            autorange: true,
            range: [x[x.length - 1], x[0]],
            rangeslider: {visible: false},
            title: 'dates'
        },
        yaxis: {
            autorange: true
        }
    };

    var trace = {
        x: x, open: open, high: high, low: low, close: close, 
        line: {color: 'rgba(31,119,180,1)'}, increasing: {line: {color: '#20a605'}}, decreasing: 
        {line: {color: '#ff0d00'}},
        xaxis: 'x', yaxis: 'y',
        type:"candlestick"
    };

    var figure = {'data': [trace], 'layout': [layout]};


    //start to make graph
    plotly.getImage(figure, imgOpts, function (err) {
        if (err) return console.log (err);

        var fileStream = fs.createWriteStream('test.png');
        imageStream.pipe(fileStream);
    });
控制台消息:

Error: Bad response status code 500
at ClientRequest.handleResponse (C:\Users\gaming 
pc\bot_code\researchbot\node_modules\plotly\index.js:237:25)
    at Object.onceWrapper (events.js:300:26)
    at ClientRequest.emit (events.js:210:5)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:583:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:115:17)
    at TLSSocket.socketOnData (_http_client.js:456:22)
    at TLSSocket.emit (events.js:210:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10) {
msg: undefined
}

我对figure的变量做得不对。布局不是数组。因此必须删除“[]”

var figure = { 'data': [trace], layout: layout};

plotly.getImage(figure, imgOpts, function (error, imageStream) {
    if (error) return console.log (error);

    var fileStream = fs.createWriteStream('test.png');
    imageStream.pipe(fileStream);
});