plotly js删除标题和标题区域 [英] plotly js remove title and title area

查看:318
本文介绍了plotly js删除标题和标题区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从情节js图表中删除标题?

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

我的示例图表如下

<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>

此图表的标题为false,我也试过
var layout = {
showtitle:false
}

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

将标题设置为null: title:''或者只是删除标题行,不显示标题,但标题区域高于标题保留的图表高度约为50px,如何删除此标题区域?

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?

推荐答案

通过从布局配置中删除标题,它将不再呈现它,但边距仍然配置为为其创建空间,您将需要覆盖这些默认边距,如此处所述。

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.

我创建了一个 jsFiddle ,显示应用的配置生成期望的输出。

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

这是它的主要内容:

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

这篇关于plotly js删除标题和标题区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆