为什么图表在拖动后变得空白

时间:2017-04-18 12:40:27

标签: javascript d3.js plotly

当我多次拖动(展开)时,图表会变为空白。我提到this code.

我想图表图应该像High Cahrt line graph一样工作。在高图表中,当我们拖动4-5次然后停止放大图并且没有得到空白图。

我想阻止它。我不想要空白。我没有得到如何阻止它。在拖动图形之前: enter image description here

拖动多次图形如下: enter image description here

我的代码是:

<script>
 var server1 = ['server1','server1','server1','server1','server1','server1','server1'];
 var trace1 = {
 x: ['2013-10-04 22:23:00', '2016-10-06 22:23:00',  '2013-11-04 22:23:00', '2013-11-07 22:23:00','2013-12-04 22:23:00', '2013-12-08 22:23:00'],
 y: [1, 3, 6,9, 4, 5],
  fill: 'tozeroy',
  fillcolor: 'red',
  text: server1,
  hoverinfo: "x+y+text",
  name:"Server 1",
  type: 'scatter',
  mode:"markers",
  marker:
  {
   size:5,
   color:"gray"
  },
  uid:"c2e171"
 };
 var layout = {
  margin: {
    l: 20,
    r: 40,
    b: 40,
    t: 10
  },
  legend: {
  "orientation": "h"
  },
 };
var data = [trace1];
Plotly.newPlot('myDiv', data,layout);

var plotDiv = document.getElementById('myDiv');
</script>

请帮帮我。我是plotly.js的新手。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您正在使用的拖动充当过滤器,以更精细的方式查看(放大)数据。每次拖动时,它都会将数据视图过滤到较少的数据点。经过几次拖动后,您已将自己过滤到比数据可容纳的更短的时间段,因此图表不会显示数据。尝试双击图表以查看(缩小)原始数据。

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
 <script type="text/javascript" src="//plot.ly/static/plotlyjs/build/plotlyjs-bundle.63b9876b722c.js"></script>
<div id="myDiv"></div>
<script>

 var trace1 = {
 x: ['2013-10-04 22:23:00', '2016-10-06 22:23:00',  '2013-11-04 22:23:00', '2013-11-07 22:23:00','2013-12-04 22:23:00', '2013-12-08 22:23:00'],
 y: [1, 3, 6,9, 4, 5],
  fill: 'tozeroy',
  fillcolor: 'red',
  text: 'server1',
  hoverinfo: "x+y+text",
  name:"Server 1",
  type: 'scatter',
  mode:"markers",
  marker:
  {
   size:5,
   color:"gray"
  },
  uid:"c2e171"
 };
 var layout = {
  margin: {
    l: 20,
    r: 40,
    b: 40,
    t: 10
  },
  legend: {
  "orientation": "h"
  },
 };
var data = [trace1];
Plotly.newPlot('myDiv', data, layout);


</script>