전체 페이지뷰

레이블이 highchart인 게시물을 표시합니다. 모든 게시물 표시
레이블이 highchart인 게시물을 표시합니다. 모든 게시물 표시

2013년 9월 11일 수요일

highchart bar chart json data


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

 var result = $.parseJSON(resultString);
var data = result.resultData.data;
// console.log ('resultString :: '+resultString);

resultString :: {"resultData":{"data":[{"deleteCount":87874,"docCount":87874,"indexName":"ISSUE"},{"deleteCount":2134,"docCount":2134,"indexName":"MESSAGE"},{"deleteCount":255,"docCount":255,"indexName":"NEWS"},{"deleteCount":1094,"docCount":1094,"indexName":"REDMINE"},{"deleteCount":3382,"docCount":3382,"indexName":"TEST"},{"deleteCount":495,"docCount":495,"indexName":"WIKI"}]}}
if (data != undefined)
{
var chartTotalData= [ ];
var chartDeleteData= [ ];

// use underscore to extract the names label
// http://underscorejs.org/  : Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming
var categories = _.pluck(data, 'indexName');
//              console.log ('categories :: '+categories);
categories :: ISSUE,MESSAGE,NEWS,REDMINE,TEST,WIKI

for(var i = 0 ; i < data.length ; i++ )
        {
            var dataOne = data[i];

            chartTotalData.push({y: parseInt(dataOne.docCount) , color: 'red' });
            chartDeleteData.push({y: parseInt(dataOne.deleteCount) , color: 'blue' });
        }

// order important
       loadBarChart(categories);

       var barChart = $('#container_bar').highcharts();

barChart.series[0].setData(chartTotalData);
barChart.series[1].setData(chartDeleteData);


function loadBarChart(categories)
{
$('#container_bar').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        subtitle: {
            text: 'Source: Wikipedia.org'
        },
        xAxis: {
            categories: categories,
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Population (millions)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            valueSuffix: ' millions'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 100,
            floating: true,
            borderWidth: 1,
            backgroundColor: '#FFFFFF',
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [
                 { data : {} , name : 'TOTAL'   , yAxis: 0},
                 { data : {} , name : 'DELETE'  , yAxis: 0},
        ]
    });
}

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
        }]
    });
}

2013년 9월 9일 월요일

learning highchart ...

reference pdf :
http://eleventyone.done.hu/OReilly.JavaScript.The.Good.Parts.May.2008.pdf

This is driven by a group of pioneers such as Douglas Crockford who is responsible for transforming the language for educating and making JavaScript a better language with his book JavaScript: The Good Parts, O'Reilly Media / Yahoo Press; and both Sam Stephenson, creator of Prototype JavaScript library (http://www.prototypejs.org), and John Resig, creator of JQuery library (http://jquery.com), who brought JavaScript into a
framework for building more complicated web frontend software


Highcharts uses jQuery as the default framework implementation, hence it only requires users to load the jQuery library before Highcharts.

To use Highcharts under the MooTools environment, users simply do the following:
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootoolsyui-
compressed.js"></script>
<script type="text/javascript" src="Highcharts-2.2.2/js/adapters/mootools-adapter.js">
</script>
<script type="text/javascript" src="Highcharts-2.2.2/js/highcharts.js"></script>

And to use Highcharts under Prototype, users need to do the following:
<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script type="text/javascript" src="Highcharts-2.2.2/js/adapters/prototype-adapter.js">
</script>
<script type="text/javascript" src="Highcharts-2.2.2/js/highcharts.js"></script>


Once the chart object is created, the graph is displayed in the browser. Within this object specifier, there are major components corresponding to the structure of the chart.

var chart = new Highcharts.Chart({
     chart: {
          ...
     },
     title: '...'
       ...
});

The renderTo option instructs Highcharts to display the graph onto the HTML <div> element with 'container' as the ID value, which is defined in the HTML <body> section. The type option is set to the default presentation type as 'spline' for any series data, as follows:
   chart: {
          renderTo: 'container'
        , type: 'spline'
   }

The options in yAxis are to assign the title of the y axis and set the minimum
possible value to zero
    yAxis: {
          title: {
              text: 'Percentage %'
          },
          min: 0
    },

The categories option in the xAxis property contains an array of x axis labels
for each data point. The best compromise is to print every third label,
(tickIntervals: 3) which causes the labels to be nicely spaced out from each other

xAxis: {
      categories: [ 'Jan 2008', 'Feb', .... ],
      tickInterval: 3
},

The plotOptions property is to control how each series is displayed according to
its type (line, pie, bar, and so on).

   plotOptions: {
      series: {
          lineWidth: 2
      }
  },

The series property is the heart of the whole configuration object, which defines all
the series data. It is an array of the series configuration objects

The data is an array of y axis values, which has the same length as the xAxis, categories array to form (x,y) data points.
series: [{
name: 'Internet Explorer',
data: [54.7, 54.7, 53.9, 54.8, 54.4, ... ]
}, {
name: 'FireFox',
data: [36.4, 36.5, 37.0, 39.1, 39.8, ... ]
}, {

For the references of all the configurations, go to http://api.highcharts.com/highcharts

Highcharts displays have three different areas—spacing area, labeling area, and plot area. The plot area is the area inside the inner rectangle that contains all the plot graphics. The labeling area is the area where labels such as title, subtitle, axis title, legend, and credits go around the plot area, so that it is between the edge of the plot area and the inner edge of the spacing area. The spacing area is the area between the container border and the outer edge of the labeling area.

chart label positioning : Automatic layout , Fixed layout

chart: {
     renderTo: 'container',
     type: ...
     marginTop: 10,
     marginRight: 0,
     spacingLeft: 30,
     spacingBottom: 0
},

from learning