plotly js remove title and title area

十年热恋 提交于 2019-12-08 15:44:39

问题


How does on remove the title from a plotly js chart?

Example chart I have is as follows

<head>
     <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<div id="myDiv" style="width: 800px; height: 400px;"></div>
<script>

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, 9],
  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:false
};

Plotly.newPlot('myDiv', data, layout);
</script>

This chart will have a title "false", I have also tried var layout = { showtitle:false }

setting the title to null: title:'' or simply removing the title line, doesn't display a title, but the title area which is approxiamtely 50px in height above the chart reserved for the title remains, how do I remove this title area?


回答1:


By removing the title from the layout config it will no longer render it however the margins are still configured to create the space for it, you will need to override those default margins as explained here.

I have create a jsFiddle showing that config applied to generate the desired output.

This is the meat of it:

var layout = {
  margin: {
    l: 50,
    r: 50,
    b: 50,
    t: 50,
    pad: 4
  }
};


来源:https://stackoverflow.com/questions/38406525/plotly-js-remove-title-and-title-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!