gpt4 book ai didi

javascript - 如何在 Angular-js 中旋转柱形图上的 x 轴标签?

转载 作者:行者123 更新时间:2023-12-03 06:21:08 24 4
gpt4 key购买 nike

我使用 Angular-nvd3.js 创建了一个柱形图。我遇到的问题是该图表的数据标签。我想垂直旋转这些标签。这是图表的示例代码以及可编辑的链接。

angular.module('mainApp.controllers')

.controller('discreteBarChartCtrl', function($scope){

$scope.options = {
chart: {
type: 'discreteBarChart',
height: 450,
margin : {
top: 20,
right: 20,
bottom: 50,
left: 55
},
x: function(d){return d.label;},
y: function(d){return d.value;},
showValues: true,
valueFormat: function(d){
return d3.format(',.4f')(d);
},
duration: 500,
xAxis: {
axisLabel: 'X Axis'
},
yAxis: {
axisLabel: 'Y Axis',
axisLabelDistance: -10
}
}
};

$scope.data = [
{
key: "Cumulative Return",
values: [
{
"label" : "A" ,
"value" : -29.765957771107
} ,
{
"label" : "B" ,
"value" : 0
} ,
{
"label" : "C" ,
"value" : 32.807804682612
} ,
{
"label" : "D" ,
"value" : 196.45946739256
} ,
{
"label" : "E" ,
"value" : 0.19434030906893
} ,
{
"label" : "F" ,
"value" : -98.079782601442
} ,
{
"label" : "G" ,
"value" : -13.925743130903
} ,
{
"label" : "H" ,
"value" : -5.1387322875705
}
]
}
]
})

http://plnkr.co/edit/6t5bky?p=preview

我希望标签与下图中的标签相同

enter image description here

最佳答案

您可以使用rotateLabels属性并设置度数,

代码:

 xAxis: {
axisLabel: 'X Axis',
rotateLabels: 90
}

这是工作 Plunker

关于javascript - 如何在 Angular-js 中旋转柱形图上的 x 轴标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38870187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com