AmChart标签被截断

3
我设置了一个指令来显示使用AmCharts的图表。除了轴标签和标题被截断的问题外,一切都工作正常,就好像它没有正确计算包括轴在内的整个图表的宽度一样。我附上了我的指令和结果的截图。您可以在y轴上最清楚地看到标签,它们只是被省略了。更改图表加载到的div的大小没有任何效果。如果我将其变大或变小,它只会改变大小,但修剪仍然存在。
'use strict';

angular.module('core').directive('amchart', ['$window',
function($window) {
return {
    template: '<div id="follower-chart" class="amchart" style="height:300px;width:960px;padding:0 15px;"></div>',
    restrict: 'EA',
    replace: false,
    scope: {
        chartType: '@',
        chartData: '='
    },
    link: function postLink(scope, element, attrs) {

        var chart = false;

        scope.$watch('chartData',function(data){

            if(data) {

                var id = $window._.uniqueId('chart_');
                /*element.attr('id', id);
                element.css({
                    height: '260px',
                    width: '870px',
                    padding: '0 0 60px 60px',
                    margin: '0 auto'
                });*/

                console.log(data);

                chart = new $window.AmCharts.AmSerialChart();

                // Data
                chart.dataProvider = data;
                chart.categoryField = 'date';
                chart.dataDateFormat = 'YYYY-MM-DD';
                chart.addClassNames = true;

                // Axis
                // Category
                var categoryAxis = chart.categoryAxis;
                categoryAxis.labelRotation = 90;
                categoryAxis.labelOffset = 35;
                categoryAxis.parseDates = true;
                categoryAxis.equalSpacing = false;

                // Value
                var valueAxis = new $window.AmCharts.ValueAxis();
                valueAxis.title = 'Followers';
                chart.addValueAxis(valueAxis);

                // GRAPH
                var graph = new $window.AmCharts.AmGraph();
                graph.id = 'g1';
                graph.bullet = 'round';
                graph.bulletBorderAlpha = 1;
                graph.bulletColor = '#FFFFFF';
                graph.bulletSize = 5;
                graph.hideBulletsCount = 50;
                graph.lineThickness = 2;
                graph.lineColor = '#1985a1';
                graph.title = 'Follower Count';
                graph.useLineColorForBulletBorder = true;
                graph.valueField = 'value';

                chart.addGraph(graph);

                // CURSOR
                var chartCursor = new $window.AmCharts.ChartCursor();
                chartCursor.cursorAlpha = 0;
                chartCursor.zoomable = false;
                chartCursor.categoryBalloonEnabled = false;
                chart.addChartCursor(chartCursor);

                chart.creditsPosition = 'bottom-right';

                // WRITE
                chart.write('follower-chart');

            }
        });
    }
};

}]);


1
有点奇怪,图表应该自动计算边距。您可以尝试设置chart.autoMargins = false,然后手动设置marginBottom / marginLeft吗? - zeroin
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - Mark
1个回答

1
在jQuery中,我使用了("autoMargins": true)这样的代码:
chart = AmCharts.makeChart("chartdiv", {
                                         "type": "serial",
                                         "addClassNames": true,
                                         "theme": "light",
                                         "autoMargins": true,
                                          ...
                                         }

我希望它能对您起作用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接