Google图表 - 中心注释

时间:2016-03-11 14:13:33

标签: google-visualization stackedbarseries

我只是想"中心"此图表中条形图中的注释。您可以看到数据如何显示在栏的末尾。这个百分比可以在栏中居中吗?

尽我所能,我无法理解。我发现了一段被描述为黑客的代码,但必须为每个图表进行自定义。我使用这段代码生成了大量的图表。任何帮助都会很受欢迎!

enter image description here

function drawVisualizationstack(qid,cdata, w,h,l,cw,pos,stacked,questioncase) {   
    pos='top';
    var data = new google.visualization.DataTable();
var e;       
for (var k=0;k<cdata.length;k++) {
    e=cdata[k];

    if (e[0]=='column') {
            if (e[2]=="tooltip") {
                data.addColumn({type:'string',role:'tooltip','p':{'html':true}});
                //data.addColumn({type: 'string', role: 'annotation','p':{'html':true}});
            }
            else if (e[2]=="annotation") {
                data.addColumn({type: 'string', role: 'annotation', p: {html: true}}); 
            }
        else {
            if (e[2]=="All") e['2']="All";
            data.addColumn(e[1],e[2]);
        }
    }   
    else {                                        
                    if (e==="" || e===undefined) {mclog('UNDEFINED DATA ROW FOR ' + qid);}
                    else {
                        data.addRow(e);
                    }
                }
    }
h=h*.75;   
var chartHeight=h-65;
var options = {
    width:500,
    height:h,
    isStacked:true,
    chartArea:{height:chartHeight,left:l,width:cw},
    backgroundColor:'transparent',
    bar:{groupWidth:'80%'},
    tooltip: {isHtml:true},
    legend:{position:'none'},
    hAxis: {title: 'Percentage',minValue:0,maxValue:100},
    hAxis: {textPosition: 'none',ticks: [0]},
    colors: ['#5d5d5d', '#002e32', '#0e1a40', '#364940', '#a9b861', '#404000', '#504000', '#604000', '#003070', '#687000'] //set default colors for charts
}}},
true,italic: true,color: '#871b47',auraColor: '#d799ae',opacity: 0.8}}
     }
var chart = new google.visualization.BarChart(document.getElementById('questchart_'+qid));
jQuery("base").attr('href',document.location);
chart.draw(data,options);

}

0 个答案:

没有答案