我有4个要比较的股票图。当我尝试为它们设置ballon
属性时,我总是会得到一些多余的属性。
我的第一个想法是仅指定一个StockGraph
,但是我得到了一个额外的对象。
let chart = window.AmCharts.makeChart("chartdiv", {
"path": AmCharts_path,
"type": "stock",
"theme": "light",
"dataSets": portfolioData.map(function (port) {
return {
"title": port.name,
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}],
"dataProvider": port.data,
"compared": true,
"categoryField": "date"
}
}),
"panels": [{
"showCategoryAxis": false,
"title": "Value",
"percentHeight": 70,
"stockGraphs": [
{
"id": "g1",
"valueField": "value",
"comparable": true,
"compareField": "value",
"balloonText": "Smart Gloabal A-[[title]]:<b>[[value]]</b>",
}
]
}],
"chartScrollbarSettings": {
"graph": "g1"
},
"chartCursorSettings": {
"valueBalloonsEnabled": true,
"fullWidth": true,
"cursorAlpha": 0.1,
"valueLineBalloonEnabled": true,
"valueLineEnabled": true,
"valueLineAlpha": 0.5
},
"listeners": [{
"event": "zoomed",
"method": this.calulateMetrics
}],
然后,我决定删除ballonText
属性。但是这个额外的对象仍然存在。
"stockGraphs": [
{
"id": "g1",
"valueField": "value",
"comparable": true,
"compareField": "value",
//"balloonText": "A-[[title]]:<b>[[value]]</b>",
"compareGraphBalloonText": "B [[title]]:<b>[[value]]</b>"
}
]
然后我决定为每个图描述逻辑,但这只会增加我的对象数量。
"stockGraphs": portfolioData.map(function (port, idx) {
return {
"id": "g"+(idx+1),
"valueField": "value",
"comparable": true,
"compareField": "value",
"balloonText": "A-[[title]]:<b>[[value]]</b>",
"compareGraphBalloonText": "B [[title]]:<b>[[value]]</b>"
}
}),
我尝试遵循官方网站上的示例,但未找到相关示例。
答案 0 :(得分:1)
第一个屏幕截图中的额外气球来自第一个dataSet
对象。默认情况下,第一个dataSet
是可见的,因此不需要将compared
设置为true;将其设置为true将会复制第一个dataSet
中的气球(如果启用,您可以在图例中看到第一个dataSet
自身的重复)。您可以通过稍微调整map
呼叫来解决此问题:
"dataSets": portfolioData.map(function (port, idx) {
return {
"title": port.name,
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}],
"dataProvider": port.data,
"compared": (idx === 0 ? false : true), //don't compare the first dataSet
"categoryField": "date"
}
}),