我正在构建一个连接到SQL数据库的ASP.NET应用程序。这是一个屏幕截图:
我想:
1)我的图表占据所有空白区域(即第二行高度)
2)在图表中添加填充,因此右侧的日期显示
我不能看到明显的。谢谢你的帮助!
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="css/nv.d3.css" rel="stylesheet" type="text/css">
<link href="Content/bootstrap.min.css" rel="stylesheet"/>
<link href="css/pikaday.css" rel="stylesheet" type="text/css" />
<link href="css/theme.css" rel="stylesheet" type="text/css" />
<link href="css/site.css" rel="stylesheet" type="text/css" />
<script src="scripts/Pikaday/moment.js" type="text/javascript" ></script>
<script src="scripts/Pikaday/pikaday.js" type="text/javascript"></script>
<script src="scripts/jquery-1.9.1.js"></script>
<script src="scripts/d3.min.js" charset="utf-8"></script>
<script src="scripts/nv.d3.min.js"></script>
<style>
.singleLabel{
min-height: 20px;
text-align: left;
font-size: large;
margin-bottom:2px;
}
.textBox{
border-left-width: 1px;
min-height: 20px;
text-align: center;
font-size: large;
margin-bottom:2px;
}
.textbox.dropDown{
text-align: right;
}
text {
font: 12px sans-serif;
}
html, body, #chart, svg{
margin: 0px;
padding: 0px;
height: 100%
width: 100%;
}
.nv-x text{
font-size: 20px;
}
.nv-y text{
font-size: 20px;
}
.nv-series text {
font-size: 20px;
}
.row {
font-size: 30px;
}
.column{
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="row"> Report from: 
<asp:TextBox ID="startDate" runat="server" columns="6" style="border:1px solid #ff0000"></asp:TextBox>
 To 
<asp:TextBox ID="endDate" runat="server" columns="6" style="border:1px solid #ff0000"></asp:TextBox>
 <input type="button" id="btGO" value="Go!" />
<%-- Date picker for start and end --%>
<script = "text/javascript">
var picker = new Pikaday({
field: document.getElementById("startDate"),
firstDay: 1,
format: "YYYY-MM-DD",
minDate: new Date('2000-01-01'),
maxDate: new Date('2020-12-31'),
yearRange: [2000,2020],
numberOfMonths: 2
});
</script>
<script = "text/javascript">
var picker = new Pikaday({
field: document.getElementById("endDate"),
firstDay: 1,
format: "YYYY-MM-DD",
minDate: new Date('2000-01-01'),
maxDate: new Date('2020-12-31'),
yearRange: [2000,2020],
numberOfMonths: 2
});
</script>
</div>
<div class="row">
<div class="col-lg-12">
<div id="chart">
<svg></svg>
</div>
</div>
</div>
<script>
d3.json('https://cdn.rawgit.com/novus/nvd3.org/master/ghpages/stackedAreaData.json', function (data) {
nv.addGraph(function () {
var chart = nv.models.stackedAreaChart()
.x(function (d) { return d[0] })
.y(function (d) { return d[1] })
.clipEdge(true)
.useInteractiveGuideline(true);
chart.xAxis
.showMaxMin(true)
.tickFormat(function (d) { return d3.time.format('%x')(new Date(d)) });
chart.yAxis
.tickFormat(d3.format(',.0f'));
d3.select('#chart svg')
.datum(data)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
})
</script>
</form>
</body>
</html>
答案 0 :(得分:1)
尝试像固定值这样的高度。我认为<div id="chart">
是你想要占据空间垂直的图表吗?
尝试使用CSS:
div.chart {
height: 80vh;
}
VH代表视口高度。所以它需要80%的屏幕高度。
对于你可以尝试的行
padding: 0 10px;
或另一个值,只是你喜欢的填充。
答案 1 :(得分:1)
您可以使用flexbox完成此操作。
中的Flexbox示例关键CSS:
#container{
display: flex;
flex-direction: column;
}
#graph{
flex-grow: 1;
}
如果这有帮助,或者您还有其他问题,请告诉我。您还需要包含here所示的前缀。