使用justgage插件动态创建仪表时,不显示值

时间:2017-06-15 16:20:03

标签: javascript jquery ajax gauge justgage

我试图动态添加量规并且实际上它可以工作但不符合预期的行为,图形显示但是值为0,即使图表显示不是0,我的仪表将显示在onclick事件div和指标是在ajax请求中创建的。

function getLocationsGauge(row, countryId) {
var chartsDataTemp;
var requestData = {
    countryId: $("#hCountryName" + countryId).val()
};
$("div").removeClass("blurELearning");
$("#gg" + countryId).addClass("blurELearning");

$.ajax({
    type: 'GET',
    dataType: 'json',
    contentType: 'application/json',
    url: '../XXX/GetLocations',
    async: false,
    data: requestData,
    success: function (chartsdata) {
        chartsDataTemp = chartsdata;
        $(".location").remove();
        $("#divLocations").remove();
        var count = chartsdata.length / 6;
        $('#countryGraphs  section:eq(' + (row) + ')').after('<div id="divLocations" class="card card-info"><div class="card-header"><strong class="header-block">' + $("#hCountryName" + countryId).val() + '</strong></div></div>');
        for (var i = 0; i <= count; i++) {
            $('#divLocations').append('<section id="location' + i + '" class="section location"><div id="rowLocation' + i + '" class="row"></div></section>');
            for (var j = i * 6; j < (i + 1) * 6; j++) {
                $('#rowLocation' + i).append('<div class="col-md-2"><div id= "ggLocation' + (j + 1) + '" ></div ></div >');
            }
        }

        for (var i = 0; i < chartsdata.length; i++) {

            var limit = Number(chartsdata[i].total) * 0.8;
            var total = Number(chartsdata[i].total);
            var approved = Number(chartsdata[i].approved);
            var name = chartsdata[i].location;
            var percentage = approved * 100 / total;
            percentage = parseFloat(Math.round(percentage * 100) / 100).toFixed(2)
            var x = "ggLocation" + (i + 1);
            objectsLocation[i] = new JustGage({
                id: x,
                value: approved,
                min: 0,
                max: total,
                gaugeWidthScale: 1,
                counter: true,
                hideInnerShadow: true,
                title: name + ' ' + percentage + '%',
                label: "approved",
                levelColors: ["#a9d70b", "#ffd6b6", "#fe9e50"],
                levelColorsGradient: true,
                pointer: true,
                pointerOptions: {
                    toplength: 1,
                    bottomlength: -40,
                    bottomwidth: 6,
                    color: '#8e8e93'
                }
            });

        }


    },
    complete: function () {

    },
    error: function () {
        alert("Error loading data for location! Please try again.");
    }
});}

Graph result

1 个答案:

答案 0 :(得分:0)

经过大量的努力,我决定直接用javascript修改html代码。 在for中创建对象(JustGage)之后,我访问了包含文本的span对象并修改了值

// Displays a permission dialog when requested for devices M and above.
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                       int[] grantResults) {
    if (requestCode == MY_PERMS_REQUEST_CAMERA) {

        // User accepts the permission(s).
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            v.startAnimation(animSlide);
            allowCamera.setVisibility(View.GONE);
            w = 1;
        } else { // User denies the permission.
            Toast.makeText(this, "Please grant the permission", Toast.LENGTH_SHORT).show();
        }
    }
}