y 轴 - 最小-最大范围 - Angular NVD3 - 折线图
y axis - min-max range - Angular NVD3 - Line chart
用法 - Angular NVD3 折线图
我正在获取数据,但是当数据为 0 时,它绘制图形并绘制 y 轴 范围 -1,0,1.
但我确实想在负 y 轴上绘图,因为我的数据永远不会为负。
X轴包含时间。
我的图表随着时间的增加而进步,问题是前几分钟数据将为 0,然后我将开始获取数据。
JavaScript代码
$scope.options = {
chart: {
type: 'lineChart',
height: 120,
margin : {
top: 8,
bottom: 30,
left:40,
right:50,
},
color: ['#e4a91d','#444fa2','#de0000']
, showLegend: false
, wrapLabels: true
, tooltips:true
, reduceXTicks: false,
x: function(d){ return d[0]; },
y: function(d){ return d[1]; },
showDistY: true,
showDistX: true,
useInteractiveGuideline: true,
transitionDuration: 10,
xAxis: {
axisLabel: '',
tickFormat: function(d) {
return d3.time.format('%H:%M')(new Date(d));
},
tickPadding: 10,
axisLabelDistance: 1,
ticks: 10,
},
yAxis: {
axisLabel: '1 / 2 / 3',
tickFormat: function(d){
return d;
},
ticks: 4,
}
}
};
Html代码
<div>
<nvd3 options="options" data="data" api="api"></nvd3>
</div>
截图
我认为这应该可行。
将这些添加到您的图表对象
<code>yDomain: [0, maxY] // maxY being whatever you want your max y value to be
我在我的图表中使用了类似的东西。在这里找到它 https://github.com/krispo/angular-nvd3/issues/47
用法 - Angular NVD3 折线图
我正在获取数据,但是当数据为 0 时,它绘制图形并绘制 y 轴 范围 -1,0,1.
但我确实想在负 y 轴上绘图,因为我的数据永远不会为负。
X轴包含时间。
我的图表随着时间的增加而进步,问题是前几分钟数据将为 0,然后我将开始获取数据。
JavaScript代码
$scope.options = {
chart: {
type: 'lineChart',
height: 120,
margin : {
top: 8,
bottom: 30,
left:40,
right:50,
},
color: ['#e4a91d','#444fa2','#de0000']
, showLegend: false
, wrapLabels: true
, tooltips:true
, reduceXTicks: false,
x: function(d){ return d[0]; },
y: function(d){ return d[1]; },
showDistY: true,
showDistX: true,
useInteractiveGuideline: true,
transitionDuration: 10,
xAxis: {
axisLabel: '',
tickFormat: function(d) {
return d3.time.format('%H:%M')(new Date(d));
},
tickPadding: 10,
axisLabelDistance: 1,
ticks: 10,
},
yAxis: {
axisLabel: '1 / 2 / 3',
tickFormat: function(d){
return d;
},
ticks: 4,
}
}
};
Html代码
<div>
<nvd3 options="options" data="data" api="api"></nvd3>
</div>
截图
我认为这应该可行。
将这些添加到您的图表对象
<code>yDomain: [0, maxY] // maxY being whatever you want your max y value to be
我在我的图表中使用了类似的东西。在这里找到它 https://github.com/krispo/angular-nvd3/issues/47