plotly - Plotly CSS 增加底线间距
问题描述
我创建了一个这样的情节
var trace2 = {
y: [12, 25, 36, 42],
x: ['20-05-2014', '20-05-2015', '20-05-2016', '20-05-2017'],
type: 'scatter'
};
var plot_data = [trace2];
Plotly.newPlot('activity-chart', plot_data);
使用上面的样本值
底部的日期字段不显示整个文本,它削减了年份。我尝试使用 chrome 的检查来编辑 css,但增加空间不会显示剪切文本。
标题也来自 csv 字段中的一个字段,因此编辑它需要更新很多字段。
解决方案
在您的标题中,您应该像这样在标题中xaxis
指定:automargin: true
standoff
xaxis: {
title: { text: 'Datetime', standoff: 50, },
automargin: true,
showgrid: false,
zeroline: false
},
由于您的代码实际上并不代表问题,因此我选择了另一个代码来演示这种效果:
<html>
<head>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="myDiv"></div>
<script>
Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/stockdata.csv', function(err, rows){
function unpack(rows, key) {
return rows.map(function(row)
{ return row[key]; });}
var trace = {
x:unpack(rows, 'Date'),
y: unpack(rows, 'IBM'),
mode: 'markers',
marker: {
size: 7,
line: {
width: 0.5},
opacity: 0.8},
type: 'scatter'
};
var layout = {
autosize: false,
height: 600,
width: 1200,
title: 'IBM Stock Data: Jan 2007 - Mar 2016',
xaxis: {tickvals:['2007-01-01', '2007-09-01', '2008-01-01', '2008-09-01', '2009-01-01', '2010-01-01', '2011-01-01', '2011-02-14', '2012-01-01', '2013-01-01', '2014-01-01', '2015-01-01', '2016-01-01'],
ticktext : ['2007', 'Financial Crisis Starts ', '2008', 'Financial Crisis Ends ', '2009', '2010', '2011', 'IBM wins Jeopardy!', '2012', '2013', '2014', '2015', '2016'],
title: {text: 'Datetime', standoff: 50, },
titlefont: { size: 30 },
automargin: true,
},
yaxis: {
title: 'Value',
titlefont: { size: 30 },
automargin: true,
},
}
Plotly.newPlot('myDiv', [trace], layout);
});
</script>
</body>
</html>
推荐阅读
- reactjs - Antdesign 选项卡反应路由器导航
- javascript - TypeError:尝试创建对象数组时分配给常量变量
- css - 未在 HTML 电子邮件中指定字体大小的风险是什么?
- python - 设计一个正则表达式以排除带有反斜杠的字符串部分
- swift - swift - 快速显示上下文菜单时如何自定义预览
- excel - Excel根据单元格VBA自动更改工作表名称
- javascript - 使用 react.js 加载数组
- python - 当数据集包含超过 50000 个缺失值时,如何使用 pandas 在数据分析中处理缺失的分类数据?
- regex - 无法找出以下的正则表达式
- python - 在 AWS Lambda (Python) 中将文件从 multipart/form-data 上传到 S3