123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
- //[Dashboard Javascript]
- //Project: Riday Admin - Responsive Admin Template
- //Primary use: Used only for the main dashboard (index.html)
- // ------------------------------
- var Widgetschart = function() {
-
- // Simple bar charts
- var _barChartWidget = function(element, barQty, height, animate, easing, duration, delay, color, tooltip) {
- if (typeof d3 == 'undefined') {
- console.warn('Warning - d3.min.js is not loaded.');
- return;
- }
- // Initialize chart only if element exsists in the DOM
- if(element) {
- // Basic setup
- // ------------------------------
- // Add data set
- var bardata = [];
- for (var i=0; i < barQty; i++) {
- bardata.push(Math.round(Math.random() * 10) + 10);
- }
- // Main variables
- var d3Container = d3.select(element),
- width = d3Container.node().getBoundingClientRect().width;
-
- // Construct scales
- // ------------------------------
- // Horizontal
- var x = d3.scale.ordinal()
- .rangeBands([0, width], 0.3);
- // Vertical
- var y = d3.scale.linear()
- .range([0, height]);
- // Set input domains
- // ------------------------------
- // Horizontal
- x.domain(d3.range(0, bardata.length));
- // Vertical
- y.domain([0, d3.max(bardata)]);
- // Create chart
- // ------------------------------
- // Add svg element
- var container = d3Container.append('svg');
- // Add SVG group
- var svg = container
- .attr('width', width)
- .attr('height', height)
- .append('g');
- //
- // Append chart elements
- //
- // Bars
- var bars = svg.selectAll('rect')
- .data(bardata)
- .enter()
- .append('rect')
- .attr('class', 'd3-random-bars')
- .attr('width', x.rangeBand())
- .attr('x', function(d,i) {
- return x(i);
- })
- .style('fill', color);
- // Tooltip
- // ------------------------------
- // Initiate
- var tip = d3.tip()
- .attr('class', 'd3-tip')
- .offset([-10, 0]);
- // Show and hide
- if(tooltip == "hours" || tooltip == "goal" || tooltip == "members") {
- bars.call(tip)
- .on('mouseover', tip.show)
- .on('mouseout', tip.hide);
- }
- // Daily meetings tooltip content
- if(tooltip == "hours") {
- tip.html(function (d, i) {
- return "<div class='text-center'>" +
- "<h6 class='mb-0'>" + d + "</h6>" +
- "<span class='font-size-16'>meetings</span>" +
- "<div class='font-size-16'>" + i + ":00" + "</div>" +
- "</div>";
- });
- }
- // Statements tooltip content
- if(tooltip == "goal") {
- tip.html(function (d, i) {
- return "<div class='text-center'>" +
- "<h6 class='mb-0'>" + d + "</h6>" +
- "<span class='font-size-16'>statements</span>" +
- "<div class='font-size-16'>" + i + ":00" + "</div>" +
- "</div>";
- });
- }
- // Online members tooltip content
- if(tooltip == "members") {
- tip.html(function (d, i) {
- return "<div class='text-center bg-dark p-5'>" +
- "<h6 class='mb-0'>" + d + "0" + "</h6>" +
- "<span class='font-size-14'>members</span>" +
- "<div class='font-size-14'>" + i + ":00" + "</div>" +
- "</div>";
- });
- }
- // Bar loading animation
- // ------------------------------
- // Choose between animated or static
- if(animate) {
- withAnimation();
- } else {
- withoutAnimation();
- }
- // Animate on load
- function withAnimation() {
- bars
- .attr('height', 0)
- .attr('y', height)
- .transition()
- .attr('height', function(d) {
- return y(d);
- })
- .attr('y', function(d) {
- return height - y(d);
- })
- .delay(function(d, i) {
- return i * delay;
- })
- .duration(duration)
- .ease(easing);
- }
- // Load without animateion
- function withoutAnimation() {
- bars
- .attr('height', function(d) {
- return y(d);
- })
- .attr('y', function(d) {
- return height - y(d);
- });
- }
- // Resize chart
- // ------------------------------
- // Call function on window resize
- $(window).on('resize', barsResize);
- // Call function on sidebar width change
- $(document).on('click', '.sidebar-control', barsResize);
- // Resize function
- //
- // Since D3 doesn't support SVG resize by default,
- // we need to manually specify parts of the graph that need to
- // be updated on window resize
- function barsResize() {
- // Layout variables
- width = d3Container.node().getBoundingClientRect().width;
- // Layout
- // -------------------------
- // Main svg width
- container.attr("width", width);
- // Width of appended group
- svg.attr("width", width);
- // Horizontal range
- x.rangeBands([0, width], 0.3);
- // Chart elements
- // -------------------------
- // Bars
- svg.selectAll('.d3-random-bars')
- .attr('width', x.rangeBand())
- .attr('x', function(d,i) {
- return x(i);
- });
- }
- }
- };
- // Simple sparklines
- var _sparklinesWidget = function(element, chartType, qty, chartHeight, interpolation, duration, interval, color) {
- if (typeof d3 == 'undefined') {
- console.warn('Warning - d3.min.js is not loaded.');
- return;
- }
- // Initialize chart only if element exsists in the DOM
- if(element) {
- // Basic setup
- // ------------------------------
- // Define main variables
- var d3Container = d3.select(element),
- margin = {top: 0, right: 0, bottom: 0, left: 0},
- width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right,
- height = chartHeight - margin.top - margin.bottom;
- // Generate random data (for demo only)
- var data = [];
- for (var i=0; i < qty; i++) {
- data.push(Math.floor(Math.random() * qty) + 5);
- }
- // Construct scales
- // ------------------------------
- // Horizontal
- var x = d3.scale.linear().range([0, width]);
- // Vertical
- var y = d3.scale.linear().range([height - 5, 5]);
- // Set input domains
- // ------------------------------
- // Horizontal
- x.domain([1, qty - 3]);
- // Vertical
- y.domain([0, qty]);
-
- // Construct chart layout
- // ------------------------------
- // Line
- var line = d3.svg.line()
- .interpolate(interpolation)
- .x(function(d, i) { return x(i); })
- .y(function(d, i) { return y(d); });
- // Area
- var area = d3.svg.area()
- .interpolate(interpolation)
- .x(function(d,i) {
- return x(i);
- })
- .y0(height)
- .y1(function(d) {
- return y(d);
- });
- // Create SVG
- // ------------------------------
- // Container
- var container = d3Container.append('svg');
- // SVG element
- var svg = container
- .attr('width', width + margin.left + margin.right)
- .attr('height', height + margin.top + margin.bottom)
- .append("g")
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
- // Add mask for animation
- // ------------------------------
- // Add clip path
- var clip = svg.append("defs")
- .append("clipPath")
- .attr('id', function(d, i) { return "load-clip-" + element.substring(1); });
- // Add clip shape
- var clips = clip.append("rect")
- .attr('class', 'load-clip')
- .attr("width", 0)
- .attr("height", height);
- // Animate mask
- clips
- .transition()
- .duration(1000)
- .ease('linear')
- .attr("width", width);
- //
- // Append chart elements
- //
- // Main path
- var path = svg.append("g")
- .attr("clip-path", function(d, i) { return "url(#load-clip-" + element.substring(1) + ")"; })
- .append("path")
- .datum(data)
- .attr("transform", "translate(" + x(0) + ",0)");
- // Add path based on chart type
- if(chartType == "area") {
- path.attr("d", area).attr('class', 'd3-area').style("fill", color); // area
- }
- else {
- path.attr("d", line).attr("class", "d3-line d3-line-medium").style('stroke', color); // line
- }
- // Animate path
- path
- .style('opacity', 0)
- .transition()
- .duration(500)
- .style('opacity', 1);
- // Set update interval. For demo only
- // ------------------------------
- setInterval(function() {
- // push a new data point onto the back
- data.push(Math.floor(Math.random() * qty) + 5);
- // pop the old data point off the front
- data.shift();
- update();
- }, interval);
- // Update random data. For demo only
- // ------------------------------
- function update() {
- // Redraw the path and slide it to the left
- path
- .attr("transform", null)
- .transition()
- .duration(duration)
- .ease("linear")
- .attr("transform", "translate(" + x(0) + ",0)");
- // Update path type
- if(chartType == "area") {
- path.attr("d", area).attr('class', 'd3-area').style("fill", color);
- }
- else {
- path.attr("d", line).attr("class", "d3-line d3-line-medium").style('stroke', color);
- }
- }
- // Resize chart
- // ------------------------------
- // Call function on window resize
- $(window).on('resize', resizeSparklines);
- // Call function on sidebar width change
- $(document).on('click', '.sidebar-control', resizeSparklines);
- // Resize function
- //
- // Since D3 doesn't support SVG resize by default,
- // we need to manually specify parts of the graph that need to
- // be updated on window resize
- function resizeSparklines() {
- // Layout variables
- width = d3Container.node().getBoundingClientRect().width - margin.left - margin.right;
- // Layout
- // -------------------------
- // Main svg width
- container.attr("width", width + margin.left + margin.right);
- // Width of appended group
- svg.attr("width", width + margin.left + margin.right);
- // Horizontal range
- x.range([0, width]);
- // Chart elements
- // -------------------------
- // Clip mask
- clips.attr("width", width);
- // Line
- svg.select(".d3-line").attr("d", line);
- // Area
- svg.select(".d3-area").attr("d", area);
- }
- }
- };
-
- //
- // Return objects assigned to module
- //
- return {
- init: function() {
- _barChartWidget("#chart_bar_basic", 24, 50, true, "elastic", 1200, 50, "#3e8ef7", "members");
- _sparklinesWidget("#sparklines_basic", "area", 30, 50, "basis", 750, 2000, "#0bb2d4");
-
- }
- }
- }();
- // Initialize module
- // ------------------------------
- // When content loaded
- document.addEventListener('DOMContentLoaded', function() {
- Widgetschart.init();
- });
- // donut chart
- $('.donut').peity('donut');
- // ------------------------------
- // Basic bar chart
- // ------------------------------
- // based on prepared DOM, initialize echarts instance
- var myChart = echarts.init(document.getElementById('basic-bar'));
- // specify chart configuration item and data
- var option = {
- // Setup grid
- grid: {
- left: '1%',
- right: '2%',
- bottom: '3%',
- containLabel: true
- },
- // Add Tooltip
- tooltip : {
- trigger: 'axis'
- },
- legend: {
- data:['Site A','Site B']
- },
- toolbox: {
- show : true,
- feature : {
- magicType : {show: true, type: ['line', 'bar']},
- restore : {show: true},
- saveAsImage : {show: true}
- }
- },
- color: ["#689f38", "#389f99"],
- calculable : true,
- xAxis : [
- {
- type : 'category',
- data : ['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sept','Oct','Nov','Dec']
- }
- ],
- yAxis : [
- {
- type : 'value'
- }
- ],
- series : [
- {
- name:'Site A',
- type:'bar',
- data:[7.2, 5.3, 6.1, 32.1, 23.1, 89.2, 158.4, 178.1, 36.4, 22.7, 7.1, 9.4],
- markPoint : {
- data : [
- {type : 'max', name: 'Max'},
- {type : 'min', name: 'Min'}
- ]
- },
- markLine : {
- data : [
- {type : 'average', name: 'Average'}
- ]
- }
- },
- {
- name:'Site B',
- type:'bar',
- data:[19.4, 7.9, 8.9, 27.9, 24.8, 88.1, 167.8, 197.5, 47.1, 16.7, 7.1, 1.5],
- markPoint : {
- data : [
- {name : 'The highest year', value : 182.2, xAxis: 7, yAxis: 183, symbolSize:18},
- {name : 'Year minimum', value : 2.3, xAxis: 11, yAxis: 3}
- ]
- },
- markLine : {
- data : [
- {type : 'average', name : 'Average'}
- ]
- }
- }
- ]
- };
- // use configuration item and data specified to show chart
- myChart.setOption(option);
|