Plotly.js x轴无法去除线条。

3

我是Plotly的新手,正在通过创建虚拟线图进行练习。但我遇到了一个问题,无法移除x轴的showline。我已将其设置为false,使用zeroline,并尝试使用linecolor使其透明,但它仍然存在。巧合的是,y轴正常工作,并且两个轴的showgrid也可以正常显示。

我猜测问题可能源于使用“类别”类型来显示季节“2017-18”,“2018-19”等,但希望有经验的Plotly用户能够确认(或提供解决方法)。谢谢。


var bedford = {
x: ['2009-10', '2010-11', '2011-12', '2012-13', '2013-14', '2014-15', '2015-16', '2016-17', '2017-18', '2018-19'],
y: [2812, 2654, 2828, 3051, 2261, 2496, 2611, 2515, 2530, 2527],
name: 'Bedford',
mode: 'lines+markers',
line: {
  color: 'rgb(128,191,255)',
  width: 2
  }
};

var birmingham = {
x: ['2009-10', '2010-11', '2011-12', '2012-13', '2013-14', '2014-15', '2015-16', '2016-17', '2017-18', '2018-19'],
y: [975, 894, 881, 971, 947, 1098, 1046, 830, 800, 676],
name: 'Birmingham',
mode: 'lines+markers',
line: {
  color: 'rgb(230,0,0)',
  width: 2
  }
};

var data = [bedford, birmingham];

var layout = {
  title: 'Second Tier Clubs Average Attendances',
  xaxis: {
    title: 'Season',
    type: 'category',
    showline: false,
    linewidth: 0
  },
  yaxis: {
    title: 'Attendance',
    range: [0, 3500],
    showline: false,
    linewidth: 0
  }
};

Plotly.newPlot('attendanceDiv', data, layout);

如果我的答案解决了您的问题,能否请您接受一下呢?这样其他用户就会知道问题已经解决了。 - schustischuster
1
没问题,schustischuster。我在Stackoverflow上非常新,还在适应中。 - Jsmith
1个回答

5

您需要设置yaxis: {zeroline: false},请查看此fiddle示例:http://jsfiddle.net/9xo3rvbg/2/

var data = [bedford, birmingham];

var layout = {
  title: 'Second Tier Clubs Average Attendances',
  xaxis: {
    title: 'Season',
    type: 'category',
    zeroline: false,
    showline: false,
  },
  yaxis: {
    title: 'Attendance',
    range: [0, 3500],
    zeroline: false,
    showline: false,
  }
};

Plotly.newPlot('attendanceDiv', data, layout);

谢谢schustischuster - 现在工作正常。很好,直接了当的答案。我之前尝试过zeroline,但由于某种原因使用了0而不是false。 - Jsmith

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接