【发布时间】:2022-08-04 09:56:16
【问题描述】:
TLDR:我有一个 NVD3 图表,它显示整个轴上的刻度线,但我想更改它,以便它只在可能的情况下显示在轴线上。
这是一个活生生的例子:
var app = angular.module(\'plunker\', [\'nvd3\']);
app.controller(\'MainCtrl\', function($scope) {
$scope.options = {
chart: {
type: \'lineChart\',
height: 450,
margin : {
top: 20,
right: 20,
bottom: 80,
left: 55
},
x: function(d){ return d.x; },
y: function(d){ return d.y; },
useInteractiveGuideline: true,
xAxis: {
axisLabel: \'Timeline\',
tickFormat: function(d) {
return d3.time.format(\'%B %d\')(new Date(d))
},
ticks: 6,
showMaxMin: false
},
yAxis: {
axisLabel: \'Molecular density (kg/m^3)\',
tickFormat: function(d){
return d3.format(\'.02f\')(d);
},
axisLabelDistance: -10,
showMaxMin: false
}
}
};
$scope.data = [{\"key\":\"K7 molecules\",\"values\":[{\"x\":1435708800000,\"y\":8},{\"x\":1435795200000,\"y\":9},{\"x\":1435881600000,\"y\":8},{\"x\":1435968000000,\"y\":8},{\"x\":1436054400000,\"y\":9},{\"x\":1436140800000,\"y\":9},{\"x\":1436227200000,\"y\":8},{\"x\":1436313600000,\"y\":8},{\"x\":1436400000000,\"y\":9},{\"x\":1436486400000,\"y\":9},{\"x\":1436572800000,\"y\":7},{\"x\":1436659200000,\"y\":8}],\"area\":true,\"color\":\"#0CB3EE\"},{\"key\":\"N41 type C molecules\",\"values\":[{\"x\":1435708800000,\"y\":8},{\"x\":1435795200000,\"y\":7},{\"x\":1435881600000,\"y\":8},{\"x\":1435968000000,\"y\":9},{\"x\":1436054400000,\"y\":7},{\"x\":1436140800000,\"y\":9},{\"x\":1436227200000,\"y\":8},{\"x\":1436313600000,\"y\":9},{\"x\":1436400000000,\"y\":9},{\"x\":1436486400000,\"y\":9},{\"x\":1436572800000,\"y\":9},{\"x\":1436659200000,\"y\":8}],\"area\":true,\"color\":\"#383838\"}];
});
<!DOCTYPE html>
<html ng-app=\"plunker\">
<head>
<meta charset=\"utf-8\" />
<title>Angular-nvD3 Line Chart</title>
<script>document.write(\'<base href=\"\' + document.location + \'\" />\');</script>
<link rel=\"stylesheet\" href=\"style.css\" />
<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.min.css\"/>
<script src=\"//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js\"></script>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js\" charset=\"utf-8\"></script>
<script src=\"https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.min.js\"></script>
<script src=\"https://rawgit.com/krispo/angular-nvd3/v1.0.1/dist/angular-nvd3.js\"></script>
<script src=\"app.js\"></script>
</head>
<body ng-controller=\"MainCtrl\">
<nvd3 options=\"options\" data=\"data\" class=\"with-3d-shadow with-transitions\"></nvd3>
</body>
</html>
-
只需在此处注意“不,NVD3 无法完成”之类的内容也是可以接受的答案。我想知道如何做到这一点,前提是它可以做到。谢谢!