Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ##############################
  2. // // // javascript library for creating charts
  3. // #############################
  4. var Chartist = require("chartist");
  5.  
  6. // ##############################
  7. // // // variables used to create animation on charts
  8. // #############################
  9. var delays = 80,
  10.   durations = 500;
  11. var delays2 = 80,
  12.   durations2 = 500;
  13.  
  14. // ##############################
  15. // // // Daily Sales
  16. // #############################
  17.  
  18.  
  19.  
  20.  
  21. // var json = httpGet("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo");
  22. // var day;
  23. // for( day in json["Time Series (5min)"]) {
  24. //   prices.push(json["Time Series (5min)"][day]["4. close"]);
  25. //   //console.log(json["Time Series (5min)"][day]["4. close"]);
  26. // }
  27.  
  28.  
  29.  
  30. var prices = [];
  31.  
  32.  
  33. const userAction = async () => {
  34.   const response = await fetch('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo');
  35.   const json = await response.json(); //extract JSON from the http response
  36.   for( let day in json["Time Series (5min)"]) {
  37.     prices.push(json["Time Series (5min)"][day]["4. close"]);
  38.     //console.log(json["Time Series (5min)"][day]["4. close"]);
  39.   }
  40. }
  41.  
  42. const dailySalesChart = {
  43.   data: {
  44.     labels: ["M", "T", "W", "T", "F", "S", "S"],
  45.     series: [prices]
  46.   },
  47.   options: {
  48.     lineSmooth: Chartist.Interpolation.cardinal({
  49.       tension: 0
  50.     }),
  51.     low: 0,
  52.     high: 50, // creative tim: we recommend you to set the high sa the biggest value + something for a better look
  53.     chartPadding: {
  54.       top: 0,
  55.       right: 0,
  56.       bottom: 0,
  57.       left: 0
  58.     }
  59.   },
  60.   // for animation
  61.   animation: {
  62.     draw: function(data) {
  63.       if (data.type === "line" || data.type === "area") {
  64.         data.element.animate({
  65.           d: {
  66.             begin: 600,
  67.             dur: 700,
  68.             from: data.path
  69.               .clone()
  70.               .scale(1, 0)
  71.               .translate(0, data.chartRect.height())
  72.               .stringify(),
  73.             to: data.path.clone().stringify(),
  74.             easing: Chartist.Svg.Easing.easeOutQuint
  75.           }
  76.         });
  77.       } else if (data.type === "point") {
  78.         data.element.animate({
  79.           opacity: {
  80.             begin: (data.index + 1) * delays,
  81.             dur: durations,
  82.             from: 0,
  83.             to: 1,
  84.             easing: "ease"
  85.           }
  86.         });
  87.       }
  88.     }
  89.   }
  90. };
  91.  
  92. // ##############################
  93. // // // Email Subscriptions
  94. // #############################
  95.  
  96. const emailsSubscriptionChart = {
  97.   data: {
  98.     labels: [
  99.       "Jan",
  100.       "Feb",
  101.       "Mar",
  102.       "Apr",
  103.       "Mai",
  104.       "Jun",
  105.       "Jul",
  106.       "Aug",
  107.       "Sep",
  108.       "Oct",
  109.       "Nov",
  110.       "Dec"
  111.     ],
  112.     series: [[542, 443, 320, 780, 553, 453, 326, 434, 568, 610, 756, 895]]
  113.   },
  114.   options: {
  115.     axisX: {
  116.       showGrid: false
  117.     },
  118.     low: 0,
  119.     high: 1000,
  120.     chartPadding: {
  121.       top: 0,
  122.       right: 5,
  123.       bottom: 0,
  124.       left: 0
  125.     }
  126.   },
  127.   responsiveOptions: [
  128.     [
  129.       "screen and (max-width: 640px)",
  130.       {
  131.         seriesBarDistance: 5,
  132.         axisX: {
  133.           labelInterpolationFnc: function(value) {
  134.             return value[0];
  135.           }
  136.         }
  137.       }
  138.     ]
  139.   ],
  140.   animation: {
  141.     draw: function(data) {
  142.       if (data.type === "bar") {
  143.         data.element.animate({
  144.           opacity: {
  145.             begin: (data.index + 1) * delays2,
  146.             dur: durations2,
  147.             from: 0,
  148.             to: 1,
  149.             easing: "ease"
  150.           }
  151.         });
  152.       }
  153.     }
  154.   }
  155. };
  156.  
  157. // ##############################
  158. // // // Completed Tasks
  159. // #############################
  160.  
  161. const completedTasksChart = {
  162.   data: {
  163.     labels: ["12am", "3pm", "6pm", "9pm", "12pm", "3am", "6am", "9am"],
  164.     series: [[230, 750, 450, 300, 280, 240, 200, 190]]
  165.   },
  166.   options: {
  167.     lineSmooth: Chartist.Interpolation.cardinal({
  168.       tension: 0
  169.     }),
  170.     low: 0,
  171.     high: 1000, // creative tim: we recommend you to set the high sa the biggest value + something for a better look
  172.     chartPadding: {
  173.       top: 0,
  174.       right: 0,
  175.       bottom: 0,
  176.       left: 0
  177.     }
  178.   },
  179.   animation: {
  180.     draw: function(data) {
  181.       if (data.type === "line" || data.type === "area") {
  182.         data.element.animate({
  183.           d: {
  184.             begin: 600,
  185.             dur: 700,
  186.             from: data.path
  187.               .clone()
  188.               .scale(1, 0)
  189.               .translate(0, data.chartRect.height())
  190.               .stringify(),
  191.             to: data.path.clone().stringify(),
  192.             easing: Chartist.Svg.Easing.easeOutQuint
  193.           }
  194.         });
  195.       } else if (data.type === "point") {
  196.         data.element.animate({
  197.           opacity: {
  198.             begin: (data.index + 1) * delays,
  199.             dur: durations,
  200.             from: 0,
  201.             to: 1,
  202.             easing: "ease"
  203.           }
  204.         });
  205.       }
  206.     }
  207.   }
  208. };
  209.  
  210. module.exports = {
  211.   dailySalesChart,
  212.   emailsSubscriptionChart,
  213.   completedTasksChart
  214. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement