Javascript amcharts 4-上一版本3用户遇到一些问题
我已经使用amcharts版本3有一段时间了,现在我想继续使用新版本4。我在复制旧版本中所做的工作时遇到了不少困难。我已经阅读了文档和示例,尝试了不同的方法,但仍然无法按照我的意愿进行操作Javascript amcharts 4-上一版本3用户遇到一些问题,javascript,amcharts,Javascript,Amcharts,我已经使用amcharts版本3有一段时间了,现在我想继续使用新版本4。我在复制旧版本中所做的工作时遇到了不少困难。我已经阅读了文档和示例,尝试了不同的方法,但仍然无法按照我的意愿进行操作 第一个“日/值”被轴切断 x轴上的日期没有以光标显示的日期为中心,这看起来很奇怪 应该只显示7个数据点(7天),但末尾总是显示额外的一天,在图表的右侧留出一个空白 我无法获取位于数据点中心的值工具提示 最后,我根本无法更改日期格式,我已经尝试了文档中显示的每个示例,用于此[修复] 我想知道这是否与在我的数
- 第一个“日/值”被轴切断
- x轴上的日期没有以光标显示的日期为中心,这看起来很奇怪
- 应该只显示7个数据点(7天),但末尾总是显示额外的一天,在图表的右侧留出一个空白
- 我无法获取位于数据点中心的值工具提示
- 最后,我根本无法更改日期格式,我已经尝试了文档中显示的每个示例,用于此[修复]
// Create chart instance
var chart = am4core.create("chart_alerts", am4charts.XYChart);
chart.data = randomData();
chart.fontSize = 12;
chart.paddingRight = 0;
chart.paddingLeft = 0;
chart.paddingTop = 20;
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.disabled = true;
dateAxis.renderer.grid.template.location = 0;
dateAxis.tooltip.background.pointerLength = 0;
dateAxis.tooltip.fontSize = 12;
//fixes the date display
dateAxis.dateFormats.setKey("day", "EEE, MMM dd");
dateAxis.periodChangeDateFormats.setKey("day", "EEE, MMM dd");
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.min = 0;
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.dateX = "timestamp";
series.dataFields.valueY = "count";
series.stroke = am4core.color("#eb4741");
series.strokeWidth = 2;
series.tensionX = 0.8;
series.fill = am4core.color("#eb4741");
series.fillOpacity = 0.1;
series.tooltipText = "Total : {valueY}";
series.tooltip.background.pointerLength = 0;
series.tooltip.fontSize = 12;
series.tooltip.background.strokeOpacity = 0;
series.tooltip.background.fillOpacity = 1;
var dropShadow = new am4core.DropShadowFilter();
dropShadow.dy = 0;
dropShadow.dx = 0;
dropShadow.opacity = 0;
series.tooltip.filters.push(dropShadow);
var bullet = series.bullets.push(new am4charts.CircleBullet());
bullet.circle.radius = 4;
bullet.circle.fill = am4core.color("#fff");
bullet.circle.strokeWidth = 2;
chart.cursor = new am4charts.XYCursor();
chart.cursor.lineX.opacity = 0;
chart.cursor.lineY.opacity = 0;
//random data generator up to 300
function randomData() {
var curr_date = $.now();
//counter
var count = 7;
//rand value
function randValue() {
return Math.floor(Math.random() * 300);
}
series = [
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()},
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()},
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()},
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()},
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()},
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()},
{'timestamp': curr_date - (--count * 86400000), 'count': randValue()}
];
return series;
}
小提琴正在演奏
编辑:我设法解决了日期格式问题,因为我遇到了其他人有同样的问题。Fiddle已经更新,但其他东西仍然有问题
- 第一个“日/值”被轴切断
- x轴上的日期没有以光标显示的日期为中心,这看起来很奇怪
minGridPosition
设置为一个小数字。但这样做的缺点是,即使没有足够的空间,也会显示每个标签,使所有标签夹在一起:
...,
xAxes: [{
type: "DateAxis",
renderer: {
grid: {
disabled: true
},
minGridDistance: 1
},
tooltip: {
fontSize: 12,
background: {
pointerLength: 0
}
}
}],
...
演示:
- 我无法获取位于数据点中心的值工具提示
pointerooritation
更改为“垂直”,而不是其侧面。此外,您可能还希望对齐文本:
...,
series: [{
type: "LineSeries",
...,
tooltip: {
pointerOrientation: "vertical",
textAlign: "middle",
textVAlign: "middle",
...
},
...
}],
...
演示:
- 第一个“日/值”被轴切断
- x轴上的日期没有以光标显示的日期为中心,这看起来很奇怪
minGridPosition
设置为一个小数字。但这样做的缺点是,即使没有足够的空间,也会显示每个标签,使所有标签夹在一起:
...,
xAxes: [{
type: "DateAxis",
renderer: {
grid: {
disabled: true
},
minGridDistance: 1
},
tooltip: {
fontSize: 12,
background: {
pointerLength: 0
}
}
}],
...
演示:
- 我无法获取位于数据点中心的值工具提示
pointerooritation
更改为“垂直”,而不是其侧面。此外,您可能还希望对齐文本:
...,
series: [{
type: "LineSeries",
...,
tooltip: {
pointerOrientation: "vertical",
textAlign: "middle",
textVAlign: "middle",
...
},
...
}],
...
演示: