-
leiz 小试身手Lv3
发表于2020-7-22 13:16
有时主题表没有绑定维表,统计图展示数据的时候,顺序乱了,那么如何能在不绑定维表的情况下,让统计图的数据按照指定顺序排列呢?
下面有一个方法可以参考一下:
如图所示,下图中数据没有绑定维表,统计图展示的顺序是错乱的:
如果要让图中的星期按照正常顺序排列,只需加上下面的脚本即可实现:
- var series_sort = ["周一","周二","周三","周四","周五","周六","周日"]; //修改成实际想要的顺序
- var chartId="HHH2";//需要进行此排序的统计图ID
- ChartInRpSheet.prototype.refresh = function(){
- this._chartdispose();
- var chartObj = this._getDom();
- var type = this.getShowType();
- if(!this.contentstring){
- ChartManagerInRpSheet._noData(chartObj);
- return;
- }
- switch(type){
- case "echarts":
- if(parseBool(chartObj.getAttribute("is3d"),false)){
- this.refreshEchart3D();
- }else{
- var datajson = JSON.parse(this.contentstring);
- if(chartObj.id==chartId)
- {
- for(var i = 0;i<datajson.xAxis.length;i++){
- function sortxAxis(a,b){
- aindex = series_sort .indexOf(a);
- bindex = series_sort .indexOf(b);
- // return a.localeCompare(b,"zh");
-
- // return a.compareTo(b);
- return aindex -bindex ;
- }
- datajson.xAxis[i].data.sort(sortxAxis);
- }
- for(var k = 0;k<datajson.series.length;k++){
- var new_data = new Array(datajson.series[k].data.length);
- for(var a = 0;a<datajson.series[k].data.length;a++){
- new_data[a] ="-";
- }
- for(var l = 0;l<datajson.series[k].data.length;l++){
- for(var i = 0;i<datajson.xAxis.length;i++){
- for(var j = 0;j<datajson.xAxis[i].data.length;j++){
- if(datajson.series[k].data[l]!="-"&&datajson.series[k].data[l].name==datajson.xAxis[i].data[j]){
- new_data[j]=datajson.series[k].data[l];
- }
- }
- }
- }
- datajson.series[k].data=new_data;
- }
- }
- this.contentstring=JSON.stringify(datajson);
- this.refreshEchart2D();
- }
- break;
- case "fusionchart":
- this.refreshFusionChart();
- break;
- case "anychart":
- this.refreshAnyChart();
- break;
- case "JS":
- this.refeshMiniChart();
- default:
- break;
- }
- };
1个回答
本帖最后由 leiz 于 2022-11-10 18:19 编辑
(不适用echarts统计图,ABI531版本后无法使用)ABI版本脚本:
var series_sort = ["周一","周二","周三","周四","周五","周六","周日"]; //修改成实际想要的顺序
var chartId="HHH3";//需要进行此排序的统计图ID
ChartInRpSheet.prototype.refresh = function(){
this._chartdispose();
var chartObj = this._getDom();
var type = this.getShowType();
if(!this.contentstring){
ChartManagerInRpSheet._noData(chartObj);
return;
}
switch(type){
case "echarts":
if(EUI.parseBool(chartObj.getAttribute("is3d"),false)){
this.refreshEchart3D();
}else{
var datajson = JSON.parse(this.contentstring);
if(chartObj.id==chartId)
{
for(var i = 0;i<datajson.xAxis.length;i++){
function sortxAxis(a,b){
aindex = series_sort .indexOf(a);
bindex = series_sort .indexOf(b);
// return a.localeCompare(b,"zh");
// return a.compareTo(b);
return aindex -bindex ;
}
datajson.xAxis.data.sort(sortxAxis);
}
for(var k = 0;k<datajson.series.length;k++){
var new_data = new Array(datajson.series[k].data.length);
for(var a = 0;a<datajson.series[k].data.length;a++){
new_data[a] ="-";
}
for(var l = 0;l<datajson.series[k].data.length;l++){
for(var i = 0;i<datajson.xAxis.length;i++){
for(var j = 0;j<datajson.xAxis.data.length;j++){
if(datajson.series[k].data[l]!="-"&&datajson.series[k].data[l].name==datajson.xAxis.data[j]){
new_data[j]=datajson.series[k].data[l];
}
}
}
}
datajson.series[k].data=new_data;
}
}
this.contentstring=JSON.stringify(datajson);
this.refreshEchart2D();
}
break;
case "fusionchart":
this.refreshFusionChart();
break;
case "anychart":
this.refreshAnyChart();
break;
case "JS":
this.refeshMiniChart();
default:
break;
}
};