[英]Amchart Dont show data where value =0
Im working in a graph where data comes from server like Object's Array. 我在一个图形中工作,其中数据来自服务器,例如对象数组。
I dont need some data to show in my graph, data where number=0, and i want to know if amchart have some function to dont show this. 我不需要一些数据在我的图表中显示,数据在number = 0处,并且我想知道amchart是否具有某些功能以不显示此数据。
Here is an example of the code: 这是代码示例:
var data =[
{'number':1, 'date':'11:00-11:59', 'duration': 3},
{'number':2, 'date':'12:00-12:59', 'duration':6},
{'number':4, 'date':'13:00-13:59', 'duration':12},
{'number':8, 'date':'14:00-14:59', 'duration':8},
{'number':0, 'date':'14:00-14:59', 'duration':0}
];
var chart = AmCharts.makeChart("chartdiv", {
"theme": "light",
"type": "serial",
"startDuration": 2,
"dataProvider": data,
"valueAxes": [{
"id": "number",
"position": "left",
"title": "N Llamadas"
},{
"id": "durationAxis",
"position": "right",
"title": "duration"
}],
"graphs": [{
"balloonText": "[[category]]: <b>[[value]]</b>",
"fillColorsField": "color",
"fillAlphas": 1,
"lineAlpha": 0.1,
"type": "column",
"valueField": "number"
},{
"bullet": "square",
"bulletBorderAlpha": 1,
"bulletBorderThickness": 1,
"dashLengthField": "dashLength",
"legendValueText": "[[value]]",
"title": "duration",
"fillAlphas": 0,
"valueField": "duration",
"valueAxis": "durationAxis"
}],
"depth3D": 20,
"angle": 30,
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "date",
"categoryAxis": {
"gridPosition": "start",
"labelRotation": 0
},
"export": {
"enabled": true
}
});
In this case i dont want to show the last item of the array because number is 0, i shouldnt create a new array for reasons project. 在这种情况下,我不想显示数组的最后一项,因为数字为0,由于项目原因,我不应该创建一个新数组。 Thanks in advance 提前致谢
Not showing a graph object when a value is 0 is pretty much impossible without modifying the array due to the bullets of the line chart (you can hide a column using alphaField, but you can't remove the bullet). 由于折线图的项目符号,在不修改数组的情况下几乎不显示数值对象几乎是不可能的(您可以使用alphaField来隐藏列,但不能删除项目符号),这是因为折线图不能修改数组。 You can write an init handler that nulls out zero values so that the chart doesn't show the point or column at all upon chart initialization: 您可以编写一个使零值无效的初始化处理程序,以使图表在图表初始化时根本不显示点或列:
//Nulls out any field that contains a zero, effectively hiding the point/column from the chart.
//Note that the category will still be visible if both points are null unless you null out that category as well.
AmCharts.addInitHandler(function(chart) {
var valueFields = chart.graphs.map(function(graph) {
return graph.valueField;
});
chart.dataProvider.forEach(function(dataItem) {
valueFields.forEach(function(valueField) {
if (dataItem[valueField] === 0) {
dataItem[valueField] = null;
}
})
})
}, ["serial"]);
Note that this will effect the data export (csv, xlsx, json) as well. 请注意,这也会影响数据导出(csv,xlsx,json)。 If you want to re-add those zero values to the data export, you can use the processData
callback in the export plugin to modify your data to re-add the zeroes: 如果要将这些零值重新添加到数据导出中,可以使用导出插件中的processData
回调来修改数据以重新添加零:
"export": {
"enabled": true,
//re-add nulled out values as zeroes for data export:
"processData": function(data, cfg) {
var valueFields = this.setup.chart.graphs.map(function(graph) {
return graph.valueField;
});
data.forEach(function(dataItem) {
valueFields.forEach(function(valueField) {
if (dataItem[valueField] == null) {
dataItem[valueField] = 0;
}
});
});
return data;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.