简体   繁体   English

饼图与高差

[英]Pie Chart with Highchatrs

My array is like this : 我的数组是这样的:

[{"label":"1","y":0,"custom":"1 : 0"},{"label":"3","y":3,"custom":"3 : 3"}]

And My jQuery code for draw chart is as below : 我的绘制图表的jQuery代码如下:

function generateGraph(value) {
    $('#loadingmessage').show();
    que_id = $(value).attr('data-id');
    que_type = $(value).attr('data-que-type');
    que_txt = $(value).parent('h4').find('.que_txt').text();

    var jsonData =
            $.ajax({
        url: "ajax.php?action=getGraphDetails",
        dataType: "json",
        data: {
            "que_id": que_id,
            "que_type": que_type,
        },
        async: false
    }).responseText;
    var obj = jQuery.parseJSON(jsonData);
    var dataXAxis = [];
    var dataYAxis = [];
    var length = 0;
    length = obj.length;
    for (var i = 0; i < length; i++) {
        dataXAxis.push(obj[i].label);
        dataYAxis.push(obj[i].y);
    }

    $('#curve_chart').highcharts({
        title: {
            text: que_txt,
            x: -20 //center
        },
        xAxis: {
            categories: dataXAxis
        },
        yAxis: {
            reversed: false
        },
        tooltip: {
            useHTML: true,
            shared: true
        },
        series: [{
                name: dataXAxis,
                data: dataYAxis,
                color: '#FF0000'
            }]
    });
}

Now my questions is set dataXaxis as name of piechart and dataYaxis as y of pie chart. 现在,我的问题是将dataXaxis设置为饼图的名称,将dataYaxis设置为饼图的y。

Please help me for the same. 请同样帮我。

Thank you in advance. 先感谢您。

Update As per comment below , you need label (your series data labels) and value.try using following: 更新根据下面的注释,您需要使用以下标签(您的系列数据标签)和value.try:

       dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.y}',

            }

see Updated fiddle as per your comment 请参阅您的评论更新的小提琴

use following code : I created an array named dataPie and pushed your json data into that . 使用以下代码:我创建了一个名为dataPie的数组,并将您的json数据放入其中。 in highcharts I called that variable. 在高图中,我称该变量。

 var dataPie =[];
var abc = [{"label":"1","y":2,"custom":"1 : 0"},   {"label":"3","y":3,"custom":"3 : 3"},{"label":"6","y":5,"custom":"3 : 3"}];
 $.each(abc,function(i,el)
{
 dataPie.push({name :el.label,y: parseFloat(el.y)});

});

See the working fiddle here 在这里查看工作的小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM