전체 페이지뷰

2013년 9월 10일 화요일

highChart pieChart json Data

I need to use Highcharts for one of my recent projects to show the pie chart results. 
Below is an example of how to set it up to create a simple pie chart and set the json data :

var result = $.parseJSON(resultString);

var data = result.resultData.data;

resultString ::{"resultData":{"data":{"TEST":"4.55","ISSUE":"88.46","WIKI":"2.15","NEWS":"0.40","MESSAGE":"2.91","free":"0.48","REDMINE":"1.04"}}}

// [ ['Firefox',   45.0],  ['IE',       26.8]   ]
var chartData= [ ];
// modify from json to map type  , 
//      you must cast value with parseFloat

Object.keys( data ).forEach(function( element, index, array ) {
chartData.push([array [ index ] , parseFloat(data [ element ])]);
});

console.log ('chartData :: '+chartData);

chartData :: TEST,4.55,ISSUE,88.46,WIKI,2.15,NEWS,0.4,MESSAGE,2.91,free,0.48,REDMINE,1.04

if (data != undefined)
{
loadPieChart(chartData);
}


function loadPieChart(chartData)
{
$('#container_pie').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Index Storage'
        },
        tooltip: {
       pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Index Storage',
            data: chartData
        }]
    });
}

댓글 없음:

댓글 쓰기