Javascript Plotly。如何创建一个情节,但实际上没有绘制它。

时间:2018-01-11 04:48:42

标签: javascript plotly

我正在使用plotly javascript绘制一些情节。但我真正需要的是网址,而且我并不需要ploly在网上绘制它。

以下是一个示例https://codepen.io/slfan2013/pen/xpWMyW。我真正需要的是url,我不希望网站上的情节显示。怎么做?谢谢!

2 个答案:

答案 0 :(得分:1)

您不需要实际绘制绘图,可以在Plotly.toImage中传递绘图数据,例如:

var trace1 = {
  x: [1, 2, 3, 4],
  y: [10, 15, 13, 17],
  mode: 'markers'
};

var trace2 = {
  x: [2, 3, 4, 5],
  y: [16, 5, 11, 10],
  mode: 'lines'
};

var trace3 = {
  x: [1, 2, 3, 4],
  y: [12, 9, 15, 12],
  mode: 'lines+markers'
};

var data = [trace1, trace2, trace3];

var layout = {
  title: 'Line and Scatter Plot'
};

Plotly.toImage({
    data: data,
    layout: layout
  }, {
    height: 600,
    width: 800
  })
  .then(
    function(url) {
      console.log(url) // this is what i really need!! I dont want it to be ploted~!

    }
  );
<head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>
  <div id="myDiv">
    <!-- Plotly chart will be drawn inside this DIV -->
  </div>
  <script>
    <!-- JAVASCRIPT CODE GOES HERE -->
  </script>
</body>

让我知道是否有帮助!

答案 1 :(得分:0)

这是我的解决方案,您可以设置div CSS属性C# WebBrowser,以便不显示图表。然后使用var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter'); onPrepare: function () { jasmine.getEnv().addReporter( new Jasmine2HtmlReporter({ savePath: __dirname+'/qualityreports/testresults/e2e', takeScreenshots: true, takeScreenshotsOnlyOnFailures: true, filePrefix: 'automationReport', consolidate: true, cleanDestination: false, consolidateAll: true }) ); }, 在获取所需内容后删除生成的图形!

总而言之,图表已创建(但不可见),获取了网址,然后图表被清除!

display:none
plotly.purge()
var trace1 = {
  x: [1, 2, 3, 4],
  y: [10, 15, 13, 17],
  mode: 'markers'
};

var trace2 = {
  x: [2, 3, 4, 5],
  y: [16, 5, 11, 10],
  mode: 'lines'
};

var trace3 = {
  x: [1, 2, 3, 4],
  y: [12, 9, 15, 12],
  mode: 'lines+markers'
};

var data = [trace1, trace2, trace3];

var layout = {
  title: 'Line and Scatter Plot'
};

Plotly.newPlot('myDiv', data, layout).then(
  function(gd) {
    Plotly.toImage(gd, {
        height: 600,
        width: 800
      })
      .then(
        function(url) {
          console.log(url); // this is what i really need!! I dont want it to be ploted~!
          Plotly.purge('myDiv');

        }
      )
  });;