Javascript AmChart标签被切掉
我有一个使用AmCharts显示图表的指令设置。除了轴标签和标题被切掉,一切都正常,因为它没有正确计算整个图表的宽度,包括轴的空间,我已经附上了我的指令和结果的屏幕截图 你可以在y轴上看到最好的标签,他们只是被错过了。更改图表加载到的div的大小没有效果。如果我把它变大或变小,它只是改变大小,但修剪仍然存在Javascript AmChart标签被切掉,javascript,angularjs,amcharts,Javascript,Angularjs,Amcharts,我有一个使用AmCharts显示图表的指令设置。除了轴标签和标题被切掉,一切都正常,因为它没有正确计算整个图表的宽度,包括轴的空间,我已经附上了我的指令和结果的屏幕截图 你可以在y轴上看到最好的标签,他们只是被错过了。更改图表加载到的div的大小没有效果。如果我把它变大或变小,它只是改变大小,但修剪仍然存在 'use strict'; angular.module('core').directive('amchart', ['$window', function($window) { ret
'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');
}
});
}
};
“严格使用”;
angular.module('core').directive('amchart',['$window',',
功能($window){
返回{
模板:“”,
限制:“EA”,
替换:false,
范围:{
图表类型:“@”,
图表数据:'='
},
链接:函数postLink(范围、元素、属性){
var图=假;
范围$watch('chartData',函数(数据){
如果(数据){
变量id=$window.\u0.uniqueId('chart_0');
/*元素属性('id',id);
element.css({
高度:“260px”,
宽度:“870px”,
填充:“0 0 60px 60px”,
边距:“0自动”
});*/
控制台日志(数据);
chart=new$window.AmCharts.AmSerialChart();
//资料
chart.dataProvider=数据;
chart.categoryField='date';
chart.dataDateFormat='YYYY-MM-DD';
chart.addClassNames=true;
//轴心
//类别
var categoryAxis=chart.categoryAxis;
categoryAxis.labelRotation=90;
categoryAxis.labelOffset=35;
categoryAxis.parseDates=true;
categoryAxis.equalspace=false;
//价值观
var valueAxis=new$window.AmCharts.valueAxis();
valueAxis.title=‘Followers’;
图表.添加valueAxis(valueAxis);
//图表
var-graph=new$window.AmCharts.AmGraph();
graph.id='g1';
graph.bullet='圆形';
图1.1α=1;
graph.bulletColor='#FFFFFF';
图1.2尺寸=5;
graph.hidebulletscont=50;
图1.lineThickness=2;
graph.lineColor='#1985a1';
graph.title='跟随者计数';
graph.useLineColorForBulletBorder=true;
graph.valueField='value';
图表。添加图表(图形);
//光标
var chartCursor=new$window.AmCharts.chartCursor();
chartCursor.cursorAlpha=0;
chartCursor.zoomable=false;
chartCursor.CategoryBalloOneEnabled=false;
chart.addChartCursor(chartCursor);
chart.creditsPosition='右下角';
//写
图表。书写(“跟随者图表”);
}
});
}
};
}])) 在我使用的jQuery上(“autoMargins”:如下所示):
我希望它对您有用。有点奇怪,图表应该自动计算保证金。您可以尝试设置chart.autoMargins=false,然后手动设置marginBottom/marginLeft吗?谢谢,这在让它看起来正确方面起了作用,但正如您所说,奇怪的是它自己没有弄清楚。我以前在Angular以外的地方使用过amCharts,没有任何问题,所以可能与此有关。
chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"addClassNames": true,
"theme": "light",
"autoMargins": true,
...
}