Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // block-ac-profit
  3. (function() {
  4.  
  5.  
  6.     var btn = $('.jsCbtn');
  7.  
  8.     btn.click(function(event) {
  9.         btn.removeClass('active');
  10.         $(this).addClass('active');
  11.     });
  12.  
  13.  
  14.     if($('div').is('.block-ac-profit')) {
  15.  
  16.         profitChrat();
  17.        
  18.     }
  19.    
  20.  
  21.     function profitChrat() {
  22.  
  23.         $.getJSON('/en/ajax/graph=graphstat', function(chartData) {
  24.  
  25.  
  26.  
  27.  
  28.         var chart = AmCharts.makeChart("profitChart", {
  29.             "type": "serial",
  30.             "theme": "light",
  31.             "marginRight": 40,
  32.             "marginLeft": 0,
  33.             "autoMarginOffset": 0,
  34.             "mouseWheelZoomEnabled":true,
  35.             "dataDateFormat": "YYYY-MM-DD",
  36.             "valueAxes": [{
  37.                 "axisAlpha": 0,
  38.                 "dashLength": 3,
  39.                 "gridAlpha": 0.16,
  40.                 "gridCount": 0,
  41.                 "id": "v1",
  42.                 "position": "right",
  43.                 "ignoreAxisWidth":true
  44.             }],
  45.             "balloon": {
  46.                 "borderThickness": 1,
  47.                 "shadowAlpha": 0
  48.             },
  49.             "graphs": [{
  50.                 "balloonText":"≈[[value]]%",
  51.                 "id": "g1",
  52.                 "bullet": "round",
  53.                 "bulletBorderAlpha": 1,
  54.                 "bulletColor": "#FFFFFF",
  55.                 "bulletSize": 5,
  56.                 "hideBulletsCount": 50,
  57.                 "lineThickness": 2,
  58.                 "title": "red line",
  59.                 "useLineColorForBulletBorder": true,
  60.                 "valueField": "value"
  61.                 //"balloonText": "<span style='font-size:18px;'>[[value]]</span>"
  62.             }],
  63.             "chartScrollbar": {
  64.                 "graph": "g1",
  65.                 "oppositeAxis":false,
  66.                 "offset":30,
  67.                 "scrollbarHeight": 80,
  68.                 "backgroundAlpha": 0,
  69.                 "selectedBackgroundAlpha": 0.1,
  70.                 "selectedBackgroundColor": "#888888",
  71.                 "graphFillAlpha": 0,
  72.                 "graphLineAlpha": 0.5,
  73.                 "selectedGraphFillAlpha": 0,
  74.                 "selectedGraphLineAlpha": 1,
  75.                 "autoGridCount":true,
  76.                 "color":"#AAAAAA"
  77.             },
  78.             "chartCursor": {
  79.                 "pan": true,
  80.                 "valueLineEnabled": true,
  81.                 "valueLineBalloonEnabled": true,
  82.                 "cursorAlpha":1,
  83.                 "cursorColor":"#258cbb",
  84.                 "limitToGraph":"g1",
  85.                 "valueLineAlpha":0.2,
  86.                 "valueZoomable":true
  87.             },
  88.             "categoryField": "month",
  89.             "categoryAxis": {
  90.                 "parseDates": true,
  91.                 "dashLength": 1,
  92.                 "minorGridEnabled": true,
  93.                 "gridAlpha": 0,
  94.                 "minorGridAlpha": 0,
  95.                 "tickLength": 0,
  96.                 "axisAlpha": 0.16
  97.             },
  98.             "export": {
  99.                 "enabled": false
  100.             },
  101.             "dataProvider": chartData,
  102.             "zoomOutOnDataUpdate": false
  103.         });
  104.        
  105.         chart.addListener("rendered", zoomChart);
  106.        
  107.         zoomChart();
  108.        
  109.         function zoomChart() {
  110.             chart.zoomToIndexes(chart.dataProvider.length - 40, chart.dataProvider.length - 1);
  111.         }
  112.  
  113.         function getYearlyData( monthly ) {
  114.             var yearly = [];
  115.             for ( var i = 0; i < monthly.length; i++ ) {
  116.                 var dp = monthly[ i ],
  117.                     next = monthly[ i + 1 ];
  118.                 if ( next === undefined || dp.month.split('-')[0] != next.month.split('-')[0] )
  119.                     yearly.push( dp );
  120.             }
  121.             return yearly;
  122.         }
  123.  
  124.         function setData(type) {
  125.             if ( type == "monthly" ) {
  126.                 chart.dataProvider = chartData;
  127.                 chart.categoryAxis.minPeriod = "MM";
  128.                 chart.chartCursor.categoryBalloonDateFormat = "MM";
  129.             }
  130.             else if( type == "yearly" ) {
  131.                 chart.dataProvider = getYearlyData( chartData );
  132.                 chart.categoryAxis.minPeriod = "YYYY";
  133.                 chart.chartCursor.categoryBalloonDateFormat = "YYYY";
  134.             }
  135.  
  136.  
  137.             chart.validateData();
  138.         };
  139.  
  140.  
  141.         $( ".year" ).click(function() {
  142.             setData("yearly");
  143.         });
  144.  
  145.         $( ".1month" ).click(function() {
  146.             setData("monthly");
  147.         });
  148.  
  149.  
  150.  
  151.  
  152.  
  153.   });
  154.  
  155.  
  156.     }
  157.  
  158. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement