| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606 |
- /*
- * Document : be_comp_charts.js
- * Author : pixelcave
- * Description: Custom JS code used in Charts Page
- */
- var BeCompCharts = function() {
- // Randomize Easy Pie Chart values
- var initRandomEasyPieChart = function(){
- jQuery('.js-pie-randomize').on('click', function(){
- jQuery(this)
- .parents('.block')
- .find('.pie-chart')
- .each(function() {
- var random = Math.floor((Math.random() * 100) + 1);
- jQuery(this)
- .data('easyPieChart')
- .update(random);
- });
- });
- };
- // jQuery Sparkline Charts, for more examples you can check out http://omnipotent.net/jquery.sparkline/#s-docs
- var initChartsSparkline = function(){
- // Chart Containers
- var slcLine1 = jQuery('.js-slc-line1');
- var slcLine2 = jQuery('.js-slc-line2');
- var slcLine3 = jQuery('.js-slc-line3');
- var slcBar1 = jQuery('.js-slc-bar1');
- var slcBar2 = jQuery('.js-slc-bar2');
- var slcBar3 = jQuery('.js-slc-bar3');
- var slcPie1 = jQuery('.js-slc-pie1');
- var slcPie2 = jQuery('.js-slc-pie2');
- var slcPie3 = jQuery('.js-slc-pie3');
- var slcTristate1 = jQuery('.js-slc-tristate1');
- var slcTristate2 = jQuery('.js-slc-tristate2');
- var slcTristate3 = jQuery('.js-slc-tristate3');
- // Line Charts
- var lineOptions = {
- type: 'line',
- width: '120px',
- height: '80px',
- tooltipOffsetX: -25,
- tooltipOffsetY: 20,
- lineColor: '#ffca28',
- fillColor: '#ffca28',
- spotColor: '#555',
- minSpotColor: '#555',
- maxSpotColor: '#555',
- highlightSpotColor: '#555',
- highlightLineColor: '#555',
- spotRadius: 2,
- tooltipPrefix: '',
- tooltipSuffix: ' Tickets',
- tooltipFormat: '{{prefix}}{{y}}{{suffix}}'
- };
- if ( slcLine1.length ) {
- slcLine1.sparkline('html', lineOptions);
- }
- lineOptions['lineColor'] = '#9ccc65';
- lineOptions['fillColor'] = '#9ccc65';
- lineOptions['tooltipPrefix'] = '$ ';
- lineOptions['tooltipSuffix'] = '';
- if ( slcLine2.length ) {
- slcLine2.sparkline('html', lineOptions);
- }
- lineOptions['lineColor'] = '#42a5f5';
- lineOptions['fillColor'] = '#42a5f5';
- lineOptions['tooltipPrefix'] = '';
- lineOptions['tooltipSuffix'] = ' Sales';
- if ( slcLine3.length ) {
- slcLine3.sparkline('html', lineOptions);
- }
- // Bar Charts
- var barOptions = {
- type: 'bar',
- barWidth: 8,
- barSpacing: 6,
- height: '80px',
- barColor: '#ffca28',
- tooltipPrefix: '',
- tooltipSuffix: ' Tickets',
- tooltipFormat: '{{prefix}}{{value}}{{suffix}}'
- };
- if ( slcBar1.length ) {
- slcBar1.sparkline('html', barOptions);
- }
- barOptions['barColor'] = '#9ccc65';
- barOptions['tooltipPrefix'] = '$ ';
- barOptions['tooltipSuffix'] = '';
- if ( slcBar2.length ) {
- slcBar2.sparkline('html', barOptions);
- }
- barOptions['barColor'] = '#42a5f5';
- barOptions['tooltipPrefix'] = '';
- barOptions['tooltipSuffix'] = ' Sales';
- if ( slcBar3.length ) {
- slcBar3.sparkline('html', barOptions);
- }
- // Pie Charts
- var pieCharts = {
- type: 'pie',
- width: '80px',
- height: '80px',
- sliceColors: ['#ffca28','#9ccc65', '#42a5f5','#ef5350'],
- highlightLighten: 1.1,
- tooltipPrefix: '',
- tooltipSuffix: ' Tickets',
- tooltipFormat: '{{prefix}}{{value}}{{suffix}}'
- };
- if ( slcPie1.length ) {
- slcPie1.sparkline('html', pieCharts);
- }
- pieCharts['tooltipPrefix'] = '$ ';
- pieCharts['tooltipSuffix'] = '';
- if ( slcPie2.length ) {
- slcPie2.sparkline('html', pieCharts);
- }
- pieCharts['tooltipPrefix'] = '';
- pieCharts['tooltipSuffix'] = ' Sales';
- if ( slcPie3.length ) {
- slcPie3.sparkline('html', pieCharts);
- }
- // Tristate Charts
- var tristateOptions = {
- type: 'tristate',
- barWidth: 8,
- barSpacing: 6,
- height: '110px',
- posBarColor: '#9ccc65',
- negBarColor: '#ef5350'
- };
- if ( slcTristate1.length ) {
- slcTristate1.sparkline('html', tristateOptions);
- }
- if ( slcTristate2.length ) {
- slcTristate2.sparkline('html', tristateOptions);
- }
- if ( slcTristate3.length ) {
- slcTristate3.sparkline('html', tristateOptions);
- }
- };
- // Chart.js Charts, for more examples you can check out http://www.chartjs.org/docs
- var initChartsChartJS = function () {
- // Set Global Chart.js configuration
- Chart.defaults.global.defaultFontColor = '#555555';
- Chart.defaults.scale.gridLines.color = "rgba(0,0,0,.04)";
- Chart.defaults.scale.gridLines.zeroLineColor = "rgba(0,0,0,.1)";
- Chart.defaults.scale.ticks.beginAtZero = true;
- Chart.defaults.global.elements.line.borderWidth = 2;
- Chart.defaults.global.elements.point.radius = 5;
- Chart.defaults.global.elements.point.hoverRadius = 7;
- Chart.defaults.global.tooltips.cornerRadius = 3;
- Chart.defaults.global.legend.labels.boxWidth = 12;
- // Get Chart Containers
- var chartLinesCon = jQuery('.js-chartjs-lines');
- var chartBarsCon = jQuery('.js-chartjs-bars');
- var chartRadarCon = jQuery('.js-chartjs-radar');
- var chartPolarCon = jQuery('.js-chartjs-polar');
- var chartPieCon = jQuery('.js-chartjs-pie');
- var chartDonutCon = jQuery('.js-chartjs-donut');
- // Set Chart and Chart Data variables
- var chartLines, chartBars, chartRadar, chartPolar, chartPie, chartDonut;
- var chartLinesBarsRadarData, chartPolarPieDonutData;
- // Lines/Bar/Radar Chart Data
- var chartLinesBarsRadarData = {
- labels: ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'],
- datasets: [
- {
- label: 'This Week',
- fill: true,
- backgroundColor: 'rgba(66,165,245,.75)',
- borderColor: 'rgba(66,165,245,1)',
- pointBackgroundColor: 'rgba(66,165,245,1)',
- pointBorderColor: '#fff',
- pointHoverBackgroundColor: '#fff',
- pointHoverBorderColor: 'rgba(66,165,245,1)',
- data: [25, 38, 62, 45, 90, 115, 130]
- },
- {
- label: 'Last Week',
- fill: true,
- backgroundColor: 'rgba(66,165,245,.25)',
- borderColor: 'rgba(66,165,245,1)',
- pointBackgroundColor: 'rgba(66,165,245,1)',
- pointBorderColor: '#fff',
- pointHoverBackgroundColor: '#fff',
- pointHoverBorderColor: 'rgba(66,165,245,1)',
- data: [112, 90, 142, 130, 170, 188, 196]
- }
- ]
- };
- // Polar/Pie/Donut Data
- var chartPolarPieDonutData = {
- labels: [
- 'Earnings',
- 'Sales',
- 'Tickets'
- ],
- datasets: [{
- data: [
- 50,
- 25,
- 25
- ],
- backgroundColor: [
- 'rgba(156,204,101,1)',
- 'rgba(255,202,40,1)',
- 'rgba(239,83,80,1)'
- ],
- hoverBackgroundColor: [
- 'rgba(156,204,101,.5)',
- 'rgba(255,202,40,.5)',
- 'rgba(239,83,80,.5)'
- ]
- }]
- };
- // Init Charts
- if ( chartLinesCon.length ) {
- chartLines = new Chart(chartLinesCon, { type: 'line', data: chartLinesBarsRadarData });
- }
- if ( chartBarsCon.length ) {
- chartBars = new Chart(chartBarsCon, { type: 'bar', data: chartLinesBarsRadarData });
- }
- if ( chartRadarCon.length ) {
- chartRadar = new Chart(chartRadarCon, { type: 'radar', data: chartLinesBarsRadarData });
- }
- if ( chartPolarCon.length ) {
- chartPolar = new Chart(chartPolarCon, { type: 'polarArea', data: chartPolarPieDonutData });
- }
- if ( chartPieCon.length ) {
- chartPie = new Chart(chartPieCon, { type: 'pie', data: chartPolarPieDonutData });
- }
- if ( chartDonutCon.length ) {
- chartDonut = new Chart(chartDonutCon, { type: 'doughnut', data: chartPolarPieDonutData });
- }
- };
- // Flot charts, for more examples you can check out http://www.flotcharts.org/flot/examples/
- var initChartsFlot = function(){
- // Get the elements where we will attach the charts
- var flotLive = jQuery('.js-flot-live');
- var flotLines = jQuery('.js-flot-lines');
- var flotStacked = jQuery('.js-flot-stacked');
- var flotPie = jQuery('.js-flot-pie');
- var flotBars = jQuery('.js-flot-bars');
- // Demo Data
- var dataEarnings = [[1, 1500], [2, 1700], [3, 1400], [4, 1900], [5, 2500], [6, 2300], [7, 2700], [8, 3200], [9, 3500], [10, 3260], [11, 4100], [12, 4600]];
- var dataSales = [[1, 500], [2, 600], [3, 400], [4, 750], [5, 1150], [6, 950], [7, 1400], [8, 1700], [9, 1800], [10, 1300], [11, 1750], [12, 2900]];
- var dataSalesBefore = [[1, 500], [4, 600], [7, 1000], [10, 600], [13, 800], [16, 1200], [19, 1500], [22, 1600], [25, 2500], [28, 2700], [31, 3500], [34, 4500]];
- var dataSalesAfter = [[2, 900], [5, 1200], [8, 2000], [11, 1200], [14, 1600], [17, 2400], [20, 3000], [23, 3200], [26, 5000], [29, 5400], [32, 7000], [35, 9000]];
- var dataMonths = [[1, 'Jan'], [2, 'Feb'], [3, 'Mar'], [4, 'Apr'], [5, 'May'], [6, 'Jun'], [7, 'Jul'], [8, 'Aug'], [9, 'Sep'], [10, 'Oct'], [11, 'Nov'], [12, 'Dec']];
- var dataMonthsBars = [[2, 'Jan'], [5, 'Feb'], [8, 'Mar'], [11, 'Apr'], [14, 'May'], [17, 'Jun'], [20, 'Jul'], [23, 'Aug'], [26, 'Sep'], [29, 'Oct'], [32, 'Nov'], [35, 'Dec']];
- // Live Chart
- var dataLive = [];
- function getRandomData() { // Random data generator
- if (dataLive.length > 0)
- dataLive = dataLive.slice(1);
- while (dataLive.length < 300) {
- var prev = dataLive.length > 0 ? dataLive[dataLive.length - 1] : 50;
- var y = prev + Math.random() * 10 - 5;
- if (y < 0)
- y = 0;
- if (y > 100)
- y = 100;
- dataLive.push(y);
- }
- var res = [];
- for (var i = 0; i < dataLive.length; ++i)
- res.push([i, dataLive[i]]);
- jQuery('.js-flot-live-info').html(y.toFixed(0) + '%'); // Show live chart info
- return res;
- }
- function updateChartLive() { // Update live chart
- chartLive.setData([getRandomData()]);
- chartLive.draw();
- setTimeout(updateChartLive, 100);
- }
- if ( flotLive.length ) {
- var chartLive = jQuery.plot(flotLive, // Init live chart
- [{ data: getRandomData() }],
- {
- series: {
- shadowSize: 0
- },
- lines: {
- show: true,
- lineWidth: 1,
- fill: true,
- fillColor: {
- colors: [{opacity: 1}, {opacity: .5}]
- }
- },
- colors: ['#42a5f5'],
- grid: {
- borderWidth: 0,
- color: '#cccccc'
- },
- yaxis: {
- show: true,
- min: 0,
- max: 100
- },
- xaxis: {
- show: false
- }
- }
- );
- updateChartLive(); // Start getting new data
- }
- // Init lines chart
- if ( flotLines.length ) {
- jQuery.plot(flotLines,
- [
- {
- label: 'Earnings',
- data: dataEarnings,
- lines: {
- show: true,
- fill: true,
- fillColor: {
- colors: [{opacity: .7}, {opacity: .7}]
- }
- },
- points: {
- show: true,
- radius: 5
- }
- },
- {
- label: 'Sales',
- data: dataSales,
- lines: {
- show: true,
- fill: true,
- fillColor: {
- colors: [{opacity: .5}, {opacity: .5}]
- }
- },
- points: {
- show: true,
- radius: 5
- }
- }
- ],
- {
- colors: ['#ffca28', '#555555'],
- legend: {
- show: true,
- position: 'nw',
- backgroundOpacity: 0
- },
- grid: {
- borderWidth: 0,
- hoverable: true,
- clickable: true
- },
- yaxis: {
- tickColor: '#ffffff',
- ticks: 3
- },
- xaxis: {
- ticks: dataMonths,
- tickColor: '#f5f5f5'
- }
- }
- );
- // Creating and attaching a tooltip to the classic chart
- var previousPoint = null, ttlabel = null;
- flotLines.bind('plothover', function(event, pos, item) {
- if (item) {
- if (previousPoint !== item.dataIndex) {
- previousPoint = item.dataIndex;
- jQuery('.js-flot-tooltip').remove();
- var x = item.datapoint[0], y = item.datapoint[1];
- if (item.seriesIndex === 0) {
- ttlabel = '$ <strong>' + y + '</strong>';
- } else if (item.seriesIndex === 1) {
- ttlabel = '<strong>' + y + '</strong> sales';
- } else {
- ttlabel = '<strong>' + y + '</strong> tickets';
- }
- jQuery('<div class="js-flot-tooltip flot-tooltip">' + ttlabel + '</div>')
- .css({top: item.pageY - 45, left: item.pageX + 5}).appendTo("body").show();
- }
- }
- else {
- jQuery('.js-flot-tooltip').remove();
- previousPoint = null;
- }
- });
- }
- // Stacked Chart
- if ( flotStacked.length ) {
- jQuery.plot(flotStacked,
- [
- {
- label: 'Sales',
- data: dataSales
- },
- {
- label: 'Earnings',
- data: dataEarnings
- }
- ],
- {
- colors: ['#555555', '#26c6da'],
- series: {
- stack: true,
- lines: {
- show: true,
- fill: true
- }
- },
- lines: {show: true,
- lineWidth: 0,
- fill: true,
- fillColor: {
- colors: [{opacity: 1}, {opacity: 1}]
- }
- },
- legend: {
- show: true,
- position: 'nw',
- sorted: true,
- backgroundOpacity: 0
- },
- grid: {
- borderWidth: 0
- },
- yaxis: {
- tickColor: '#ffffff',
- ticks: 3
- },
- xaxis: {
- ticks: dataMonths,
- tickColor: '#f5f5f5'
- }
- }
- );
- }
- // Bars Chart
- if ( flotBars.length ) {
- jQuery.plot(flotBars,
- [
- {
- label: 'Sales Before Release',
- data: dataSalesBefore,
- bars: {
- show: true,
- lineWidth: 0,
- fillColor: {
- colors: [{opacity: .75}, {opacity: .75}]
- }
- }
- },
- {
- label: 'Sales After Release',
- data: dataSalesAfter,
- bars: {
- show: true,
- lineWidth: 0,
- fillColor: {
- colors: [{opacity: .75}, {opacity: .75}]
- }
- }
- }
- ],
- {
- colors: ['#ef5350', '#9ccc65'],
- legend: {
- show: true,
- position: 'nw',
- backgroundOpacity: 0
- },
- grid: {
- borderWidth: 0
- },
- yaxis: {
- ticks: 3,
- tickColor: '#f5f5f5'
- },
- xaxis: {
- ticks: dataMonthsBars,
- tickColor: '#f5f5f5'
- }
- }
- );
- }
- // Pie Chart
- if ( flotPie.length ) {
- jQuery.plot(flotPie,
- [
- {
- label: 'Sales',
- data: 15
- },
- {
- label: 'Tickets',
- data: 12
- },
- {
- label: 'Earnings',
- data: 73
- }
- ],
- {
- colors: ['#26c6da', '#ffca28', '#9ccc65'],
- legend: {show: false},
- series: {
- pie: {
- show: true,
- radius: 1,
- label: {
- show: true,
- radius: 2/3,
- formatter: function(label, pieSeries) {
- return '<div class="flot-pie-label">' + label + '<br>' + Math.round(pieSeries.percent) + '%</div>';
- },
- background: {
- opacity: .75,
- color: '#000000'
- }
- }
- }
- }
- }
- );
- }
- };
- return {
- init: function () {
- // Randomize Easy Pie values functionality
- initRandomEasyPieChart();
- // Init Sparkline Charts
- initChartsSparkline();
- // Init Chart.js Charts
- initChartsChartJS();
- // Init Flot Charts
- initChartsFlot();
- }
- };
- }();
- // Initialize when page loads
- jQuery(function(){ BeCompCharts.init(); });
|