File: //home/arjun/projects/buyercall_new/buyercall/buyercall/static/js/pages/compCharts.js
/*
* Document : compCharts.js
* Author : pixelcave
* Description: Custom javascript code used in Charts page
*/
var CompCharts = function() {
// Get random number function from a given range
var getRandomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
return {
init: function() {
/*
* Flot Jquery plugin is used for charts
*
* For more examples or getting extra plugins you can check http://www.flotcharts.org/
* Plugins included in this template: pie, resize, stack, time
*/
// Get the elements where we will attach the charts
var chartClassic = $('#chart-classic');
var chartStacked = $('#chart-stacked');
var chartBars = $('#chart-bars');
var chartPie = $('#chart-pie');
// Random data for the charts
var dataEarnings = [[1, 1800], [2, 1600], [3, 1400], [4, 1900], [5, 1600], [6, 2100], [7, 2900], [8, 2100], [9, 3200], [10, 3500], [11, 3200], [12, 4000]];
var dataSales = [[1, 900], [2, 800], [3, 700], [4, 950], [5, 800], [6, 1050], [7, 1450], [8, 1050], [9, 1600], [10, 1750], [11, 1600], [12, 2000]];
var dataSales2 = [[1, 900], [3, 800], [5, 700], [7, 950], [9, 800], [11, 1050], [13, 1450], [15, 1050]];
// Array with month labels used in Classic and Stacked chart
var chartMonths = [[1, 'Jan'], [2, 'Feb'], [3, 'Mar'], [4, 'Apr'], [5, 'May'], [6, 'Jun'], [7, 'Jul'], [8, 'Aug'], [9, 'Sep'], [10, 'Oct'], [11, 'Nov'], [12, 'Dec']];
// Classic Chart
$.plot(chartClassic,
[
{
label: 'Earnings',
data: dataEarnings,
lines: {show: true, fill: true, fillColor: {colors: [{opacity: 0.5}, {opacity: 0.5}]}},
points: {show: true, radius: 7}
},
{
label: 'Sales',
data: dataSales,
lines: {show: true, fill: true, fillColor: {colors: [{opacity: 0.2}, {opacity: 0.2}]}},
points: {show: true, radius: 5}
}
],
{
colors: ['#9ddd7b', '#000000'],
legend: {show: true, position: 'nw', margin: [0, 0]},
grid: {borderWidth: 0, hoverable: true, clickable: true},
yaxis: {show: false},
xaxis: {ticks: chartMonths, tickColor: '#ffffff'}
}
);
// Creating and attaching a tooltip to the classic chart
var previousPoint = null, ttlabel = null;
chartClassic.bind('plothover', function(event, pos, item) {
if (item) {
if (previousPoint !== item.dataIndex) {
previousPoint = item.dataIndex;
$('#chart-tooltip').remove();
var x = item.datapoint[0], y = item.datapoint[1];
if (item.seriesIndex === 1) {
ttlabel = '<strong>' + y + '</strong> sales';
} else {
ttlabel = '$ <strong>' + y + '</strong>';
}
$('<div id="chart-tooltip" class="chart-tooltip">' + ttlabel + '</div>')
.css({top: item.pageY - 45, left: item.pageX + 5}).appendTo("body").show();
}
}
else {
$('#chart-tooltip').remove();
previousPoint = null;
}
});
// Pie Chart
$.plot(chartPie,
[
{label: 'Sales', data: 33},
{label: 'Support', data: 33},
{label: 'Earnings', data: 33}
],
{
colors: ['#9ddd7b', '#dd817b', '#51b7dd'],
legend: {show: false},
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 3 / 4,
formatter: function(label, pieSeries) {
return '<div class="chart-pie-label">' + label + '<br>' + Math.round(pieSeries.percent) + '%</div>';
},
background: {opacity: 0.75, color: '#000000'}
}
}
}
}
);
// Bars Chart
$.plot(chartBars,
[
{
label: 'Sales',
data: dataSales2,
bars: {show: true, lineWidth: 0, fillColor: {colors: [{opacity: 0.9}, {opacity: 0.9}]}}
}
],
{
colors: ['#2eb398'],
legend: {show: true, position: 'nw', margin: [0, 25]},
grid: {borderWidth: 0},
yaxis: {ticks: 4, tickColor: '#eeeeee'},
xaxis: {show: false}
}
);
// Stacked Chart
$.plot(chartStacked,
[{label: 'Sales', data: dataSales}, {label: 'Earnings', data: dataEarnings}],
{
colors: ['#cccccc', '#51b7dd'],
series: {stack: true, lines: {show: true, fill: true}},
lines: {show: true, lineWidth: 0, fill: true, fillColor: {colors: [{opacity: 0.75}, {opacity: 0.75}]}},
legend: {show: true, position: 'nw', margin: [0, 0], sorted: true},
grid: {borderWidth: 0},
yaxis: {show: false},
xaxis: {ticks: chartMonths, tickColor: '#ffffff'}
}
);
/* Mini Bar/Line Charts with jquery.sparkline plugin, for more examples you can check out http://omnipotent.net/jquery.sparkline/#s-about */
var miniChartBarOptions = {
type: 'bar',
barWidth: 7,
barSpacing: 6,
height: '70px',
tooltipOffsetX: -25,
tooltipOffsetY: 20,
barColor: '#dd817b',
tooltipPrefix: '',
tooltipSuffix: ' Projects',
tooltipFormat: '{{prefix}}{{value}}{{suffix}}'
};
$('#mini-chart-bar1').sparkline('html', miniChartBarOptions);
miniChartBarOptions['barColor'] = '#fa9c61';
miniChartBarOptions['tooltipPrefix'] = '$ ';
miniChartBarOptions['tooltipSuffix'] = '';
$('#mini-chart-bar2').sparkline('html', miniChartBarOptions);
miniChartBarOptions['barColor'] = '#51b7dd';
miniChartBarOptions['tooltipPrefix'] = '';
miniChartBarOptions['tooltipSuffix'] = ' Updates';
$('#mini-chart-bar3').sparkline('html', miniChartBarOptions);
miniChartBarOptions['barColor'] = '#9ddd7b';
miniChartBarOptions['tooltipPrefix'] = '';
miniChartBarOptions['tooltipSuffix'] = ' Tickets';
$('#mini-chart-bar4').sparkline('html', miniChartBarOptions);
var miniChartLineOptions = {
type: 'line',
width: '100px',
height: '70px',
tooltipOffsetX: -25,
tooltipOffsetY: 20,
lineColor: '#dd817b',
fillColor: '#dd817b',
spotColor: '#333333',
minSpotColor: '#333333',
maxSpotColor: '#333333',
highlightSpotColor: '#333333',
highlightLineColor: '#333333',
spotRadius: 3,
tooltipPrefix: '',
tooltipSuffix: ' Projects',
tooltipFormat: '{{prefix}}{{y}}{{suffix}}'
};
$('#mini-chart-line1').sparkline('html', miniChartLineOptions);
miniChartLineOptions['lineColor'] = '#fa9c61';
miniChartLineOptions['fillColor'] = '#fa9c61';
miniChartLineOptions['tooltipPrefix'] = '$ ';
miniChartLineOptions['tooltipSuffix'] = '';
$('#mini-chart-line2').sparkline('html', miniChartLineOptions);
miniChartLineOptions['lineColor'] = '#51b7dd';
miniChartLineOptions['fillColor'] = '#51b7dd';
miniChartLineOptions['tooltipPrefix'] = '';
miniChartLineOptions['tooltipSuffix'] = ' Updates';
$('#mini-chart-line3').sparkline('html', miniChartLineOptions);
miniChartLineOptions['lineColor'] = '#9ddd7b';
miniChartLineOptions['fillColor'] = '#9ddd7b';
miniChartLineOptions['tooltipPrefix'] = '';
miniChartLineOptions['tooltipSuffix'] = ' Tickets';
$('#mini-chart-line4').sparkline('html', miniChartLineOptions);
// Randomize easy pie charts values
var random;
$('.toggle-pies').click(function() {
$('.pie-chart').each(function() {
random = getRandomInt(1, 100);
$(this).data('easyPieChart').update(random);
$(this).find('span').html('<strong>' + random + '</strong>' + '%');
});
});
}
};
}();