javascript - Google 饼图尝试在 API 完成加载之前绘制

标签 javascript google-visualization

我在使用 Google 图表时遇到了一些问题。这是我的饼图的代码:

编辑部分

function displayExistHospital(){
queryTask = new esri.tasks.QueryTask(overlayURLs["moh_hospital_WSA2"] + "/10");
query = new esri.tasks.Query();
query.returnGeometry = false;
query.where = "1=1";
query.outFields = ["*"];

queryTask.execute(query, getExistHospitalData);

document.getElementById("tabsLabel").style.display = "block";
document.getElementById("tabsLabel3").innerHTML = "Age > 60";
document.getElementById("tabsLabel2").innerHTML = "SCPR";
document.getElementById("tabsLabel1").innerHTML = "Total Pop";

}
google.load("visualization", "1", {packages:["corechart"], callback: displayExistHospital});

var arrList = [];
function getExistHospitalData(results){
arrList = [];
var features = results.features;
dojo.forEach(features, function(feature){
var tempArr = [];
    var total_SCPR = feature.attributes.SUM_SUM_TOTAL_SCPR;
    var total_NR = feature.attributes.SUM_SUM_TOTAL_NR;
    var time = feature.attributes.FIRST_E_BREAK;
    tempArr.push(time,total_SCPR,total_NR);
    arrList.push(tempArr);
});

displayExistHospitalGraph(arrList); 
}

function displayExistHospitalGraph(arrListData){
var total_ten = parseInt(arrListData[0][1]) + parseInt(arrListData[0][2]);
var total_tentoFifteen = arrListData[1][1] + arrListData[1][2];
var total_fifteenTwenty = arrListData[2][1] + arrListData[2][2];
var total_greaterTwenty = arrListData[3][1] + arrListData[3][2];

var ppl_num = total_ten + total_tentoFifteen; 
var total_pop = total_ten + total_tentoFifteen + total_fifteenTwenty + total_greaterTwenty;
var dataOne = google.visualization.arrayToDataTable([
    ['Population', 'Percentage'],
    ['<10 mins' +getPercentageInString(total_ten,total_pop) , total_ten],
    ['10 - 15 mins' +getPercentageInString(total_tentoFifteen,total_pop), total_tentoFifteen],
    ['15 - 20 mins' +getPercentageInString(total_fifteenTwenty,total_pop), total_fifteenTwenty],
    ['>20 mins' +getPercentageInString(total_greaterTwenty,total_pop) , total_greaterTwenty],   
]);
var percentage = (((total_ten / total_pop) + (total_tentoFifteen / total_pop)) * 100).toFixed(1);
var title = "Total Population ("+total_pop.toLocaleString()+") Catchment By Drive-Time(Existing)";

var optionsOne = {
    chartArea: {
        width: 350,
        height: 200,
        top: 20, 
        left: 10 
    },
    fontName: 'Arial',
    fontSize: getFontSize(),
isStacked:false,
    title: title,
    width: 400,
height: 200,
    sliceVisibilityThreshold: 0,
    colors:['#004CA8','#437DC4','#96B8E0','#FFFFFF']
};

document.getElementById('hospitalBoxContent').innerHTML= "</br><p ><span style='font-size:2em; color:#00297A; font-family:ArialVerdana; font-weight:bold;'>"+percentage+"% ("+ppl_num.toLocaleString()+")</span > of residents stay within <span style='font-size:2em; color:#00297A; font-family:ArialVerdana; font-weight:bold;'>15-min</span> drive-time to a public hospital </p><br/>";
var chart = new google.visualization.PieChart(document.getElementById('displayHospitalGraph'));
chart.draw(dataOne, optionsOne);

}

图表有效,但饼图上的百分比不知何故被 chop ,如下图所示:

enter image description here

我想知道有没有办法调整百分比,例如,将它移近中心,这样它就不会被切断?我知道原因是因为图表试图在 API 完成加载之前绘制,因为这只会在第一次加载时发生。切换几个图表后,百分比标签将很好地放置在图表内。

感谢@asgallant 和@Yoann,他们帮助我发现了错误,但在添加代码后,问题仍然没有解决。

提前致谢。

最佳答案

请将最后一个颜色#FFFFFF 更改为任何其他颜色#FFFFFF 此颜色与背景相同

关于javascript - Google 饼图尝试在 API 完成加载之前绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23234628/

相关文章:

javascript - 如何设置信息框的动态像素偏移?

javascript - 单击按钮时 JQuery OnClick 不起作用

javascript chart.js data.addRow 不从 json 中读取数字

google-visualization - 谷歌图表轴标题

javascript - 从 iframe 调用在父级中定义的 javascript 方法

javascript - 使用 jQuery 切换复杂弹出式样式 css 菜单的可见性

javascript - Bootstrap Datetimepicker 模态日历位置追加不起作用

javascript - Google 可视化多重查询(电子表格)

javascript - Google Graphs 显示散点上的小数位

javascript - 将自定义文本添加到谷歌饼图中的值?