gpt4 book ai didi

javascript - Amcharts 图表 - 图表列的超链接到自定义 URL 以在新选项卡/窗口中打开

转载 作者:行者123 更新时间:2023-11-30 21:03:14 25 4
gpt4 key购买 nike

我正在尝试制作一个 amcharts 图表,其中包含链接到自定义 url 的列,并希望 url 在新选项卡/窗口中打开。我尝试将此代码添加到图形对象,但它不起作用,它在同一选项卡/窗口中打开链接 -

"listeners": [{
"event": "clickItem",
"method": function(event) {
window.open(event.serialDataItem.dataContext.url, '_blank');
}
}],

请告诉我做错了什么。我不想使用 Jquery,而且我是 javascript 的新手。

这是我的代码片段-

var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"dataProvider": [{
"country": "USA",
"visits": 2025,
"url": "https://en.wikipedia.org/wiki/United_States"
}, {
"country": "China",
"visits": 1882,
"url": "https://en.wikipedia.org/wiki/China"
}, {
"country": "Japan",
"visits": 1809,
"url": "https://en.wikipedia.org/wiki/Japan"
}, {
"country": "Germany",
"visits": 1322,
"url": "https://en.wikipedia.org/wiki/Germany"
}, {
"country": "France",
"visits": 1114,
"url": "https://en.wikipedia.org/wiki/France"
}, {
"country": "India",
"visits": 984,
"url": "https://en.wikipedia.org/wiki/India"
}, {
"country": "Spain",
"visits": 711,
"url": "https://en.wikipedia.org/wiki/Spain"
}],
"valueAxes": [{
"gridColor": "#FFFFFF",
"gridAlpha": 0.2,
"dashLength": 0
}],
"gridAboveGraphs": true,
"startDuration": 1,
"graphs": [{
"balloonText": "[[category]]: <b>[[value]]</b>",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"type": "column",
"valueField": "visits",
"listeners": [{
"event": "clickItem",
"method": function(event) {
window.open(event.serialDataItem.dataContext.url, '_blank');
}
}],
"urlField": "url"
}],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "country",
"categoryAxis": {
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start",
"tickLength": 20
}
});
html, body {
width: 100%;
height: 100%;
margin: 0px;
}

#chartdiv {
width: 100%;
height: 100%;
}
<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/serial.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>

<div id="chartdiv"></div>

最佳答案

您可以使用 urlTarget比如:

var chart = AmCharts.makeChart("chartdiv", {
"graphs": [{
"balloonText": "[[category]]: <b>[[value]]</b>",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"type": "column",
"valueField": "visits",
"urlField": "url",
"urlTarget": "_blank"
}],
...
};

关于javascript - Amcharts 图表 - 图表列的超链接到自定义 URL 以在新选项卡/窗口中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46898995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com