简体   繁体   English

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

[英]How can I rotate x-axis labels on a column chart in Angular-js?

I have created a column chart using Angular-nvd3.js. 我已经使用Angular-nvd3.js创建了一个柱形图。 The problem I'm having is with the data labels of that chart. 我遇到的问题是该图表的数据标签。 I want to rotate these labels vertically. 我想垂直旋转这些标签。 This is the sample code of the chart and an editable link as well. 这是图表的示例代码,也是一个可编辑的链接。

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 http://plnkr.co/edit/6t5bky?p=预览

I want the labels to be the same as in the following graph in the picture 我希望标签与图片中的下图相同

在此处输入图片说明

You can use the rotateLabels attribute and set the degree, 您可以使用rotateLabels属性并设置度数,

Code: 码:

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

Here is the working Plunker 这是工作中的Plunker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将X轴标签旋转到条形图中的条形图上? - How to rotate X-axis labels onto the bar in bar chart? 如何使用nvd3在柱形图上定位旋转的x轴标签? - How can I position rotated x-axis labels on column chart using nvd3? 如何使用Highcharts在柱形图中指定柱相对于X轴标签的位置? - How can I specify the position of the columns relative to the X-axis labels in a column chart using Highcharts? 如何在 x 轴和 y 轴上添加轴标签? (图表.js) - How do you add Axis Labels on to both x-axis and y-axis? (Chart.js) Chart.js带有客户X轴标签的气泡图 - Chart.js Bubble chart with custome X-axis labels 在Chart.js中修改条形图的X轴标签2 - Modifying the X-Axis Labels of a Bar chart in Chart.js 2 如何自定义 y 轴标签并从 Chart js 中 x 轴的数据范围中随机选取值 - How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js 无法弄清楚如何使用 Chart.js 跳过 x 轴上的第一个数据点和 X 轴上的标签跳过倒数第二个数据点 - Can't figure out how to skip first datapoint on the x-axis and labels on X-axis skip second-to-last datapoint with Chart.js Highcharts-如何在日期时间x轴上居中放置标签? - Highcharts - how can I center labels on a datetime x-axis? c3 js:如何在 X 轴标签上按年份分组? - c3 js: How can I group by Year on the X-axis labels?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM