带有向下钻取的 Amchart 图表工作正常,但“后退”按钮不起作用
Amchart graph with drill down is working fine but Back button is not working
<!DOCTYPE>
<html>
<head>
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="https://www.amcharts.com/lib/3/amstock.js"></script>
</head>
<body>
<div id="chartdiv" style="width: 100%; height: 355px;"></div>
<script>
var chart;
var chartData = [{
country: "Somaliland",
visits: 4025,
"allLabels": [{
"text": "",
"x": 10,
"y": 15,
"url": "#"
}],
subdata: [
{ country: "Gabiley", visits: 1000, subdata: [
{ country: "Arabsiyo", visits: 1000 },
{ country: "Gabilay", visits: 785 },
{ country: "Wajale", visits: 1000 },
] },
{ country: "Sanaag", visits: 785, subdata: [
{ country: "Ceeri Gaabo", visits: 1000 },
] },
{ country: "M.Jeex", visits: 501, subdata: [
{ country: "Hargeysa", visits: 1000 },
] }
]},
{
country: "Puntland",
visits: 3882,
subdata: [
{ country: "Bari", visits: 1000, subdata: [
{ country: "BOSASO", visits: 500 },
{ country: "Balibusle", visits: 785 },
] },
{ title : "title1",
country: "Mudug", visits: 785, subdata: [
{ country: "Sheerbi", visits: 1000 },
{ country: "Ufayn", visits: 1000 },
] }
]
},
];
AmCharts.ready(function() {
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.dataProvider = chartData;
chart.categoryField = "country";
chart.startDuration = 0;
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.labelRotation = 0;
categoryAxis.gridPosition = "start";
// value
// in case you don't want to change default settings of value axis,
// you don't need to create it, as one value axis is created automatically.
// GRAPH
var graph = new AmCharts.AmGraph();
graph.valueField = "visits";
graph.balloonText = "[[category]]: [[value]]";
graph.titleField = "title";
graph.type = "column";
graph.lineAlpha = 0;
graph.fillAlphas = 0.8;
chart.addGraph(graph);
chart.angle = 30;
chart.depth3D = 15;
chart.drillLevels = [{
"title": "Average Revenue Per User",
"data": chartData
}];
chart.addListener("clickGraphItem", function (event) {
// let's look if the clicked graph item had any subdata to drill-down into
if (event.item.dataContext.subdata != undefined) {
// wow it has!
// let's set that as chart's dataProvider
// replace data
// replace title
// add back link
// let's add a label to go back to yearly data
// add back link
// let's add a label to go back to yearly data
event.chart.addLabel(
0, 25,
"<<< Go back",
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
'javascript:drillUp();');
event.chart.dataProvider = event.item.dataContext.subdata;
event.chart.validateData();
}
event.chart.allLabels[0].text = "Go Back " + event.chart.title[0].text;
});
chart.write("chartdiv");
});
function drillUp() {
// get level
chart.drillLevels.pop();
var level = chart.drillLevels[chart.drillLevels.length - 1];
// replace data
chart.dataProvider = level.data;
// replace title
chart.titles[0].text = level.title;
// remove labels
if (chart.drillLevels.length === 1)
chart.clearLabels();
// take in data and animate
chart.validateData();
chart.animateAgain();
}
</script>
</body>
</html>
我已经粘贴了上面的代码。当我运行图形时,它可以通过向下钻取正常工作,但后退按钮不起作用。
当控制台显示"TypeError: event.chart.title is undefined"时。
正如错误消息明确指出的那样,属性chart.title
不存在。
因此,您只需再次查找文档或使用控制台查看chart
对象包含的内容以及其中的标题......
这样,我现在知道您只需要使用chart.titles[0]
而不是chart.title[0]
!
相关文章:
- 带有向下钻取的 Amchart 图表工作正常,但“后退”按钮不起作用
- 使用动画时Jquery后退按钮不起作用
- 禁用浏览器中的后退按钮不起作用
- 后退按钮在jquerymobile中不起作用
- 锚链接是指在浏览器刷新、后退和前进时不起作用的页面部分
- JQuery & history.js后退按钮不起作用
- Ajax + 浏览器后退按钮 = 复选框不起作用
- 按下后退并调用历史记录后();History.pushstate没有实例化/不起作用
- 历史记录 API 不起作用(后退/前进)
- 滑动面板菜单后退按钮不起作用
- 点击浏览器的后退按钮后,身体加载在火狐中不起作用
- 后退不起作用
- 后退按钮在Ipad上不起作用'的默认浏览器(Safari)
- 浏览器后退按钮没有'当内容加载到iframe中时不起作用
- 在Android应用程序(Phonegap&AngularJS)中按下后退按钮时应用程序退出不起作用
- 当按下后退按钮时,jQuery切换不起作用
- Jquery Mobile后退按钮获胜'不起作用
- 如果多页面是在jQuery中完成的,后退按钮在浏览器中不起作用
- 定位后后退按钮不起作用.在Angular应用中重新加载
- Angularjs -浏览器后退按钮不起作用