Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ##############################
- // // // javascript library for creating charts
- // #############################
- var Chartist = require("chartist");
- // ##############################
- // // // variables used to create animation on charts
- // #############################
- var delays = 80,
- durations = 500;
- var delays2 = 80,
- durations2 = 500;
- // ##############################
- // // // Daily Sales
- // #############################
- // var json = httpGet("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo");
- // var day;
- // for( day in json["Time Series (5min)"]) {
- // prices.push(json["Time Series (5min)"][day]["4. close"]);
- // //console.log(json["Time Series (5min)"][day]["4. close"]);
- // }
- var prices = [];
- const userAction = async () => {
- const response = await fetch('https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=5min&apikey=demo');
- const json = await response.json(); //extract JSON from the http response
- for( let day in json["Time Series (5min)"]) {
- prices.push(json["Time Series (5min)"][day]["4. close"]);
- //console.log(json["Time Series (5min)"][day]["4. close"]);
- }
- }
- const dailySalesChart = {
- data: {
- labels: ["M", "T", "W", "T", "F", "S", "S"],
- series: [prices]
- },
- options: {
- lineSmooth: Chartist.Interpolation.cardinal({
- tension: 0
- }),
- low: 0,
- high: 50, // creative tim: we recommend you to set the high sa the biggest value + something for a better look
- chartPadding: {
- top: 0,
- right: 0,
- bottom: 0,
- left: 0
- }
- },
- // for animation
- animation: {
- draw: function(data) {
- if (data.type === "line" || data.type === "area") {
- data.element.animate({
- d: {
- begin: 600,
- dur: 700,
- from: data.path
- .clone()
- .scale(1, 0)
- .translate(0, data.chartRect.height())
- .stringify(),
- to: data.path.clone().stringify(),
- easing: Chartist.Svg.Easing.easeOutQuint
- }
- });
- } else if (data.type === "point") {
- data.element.animate({
- opacity: {
- begin: (data.index + 1) * delays,
- dur: durations,
- from: 0,
- to: 1,
- easing: "ease"
- }
- });
- }
- }
- }
- };
- // ##############################
- // // // Email Subscriptions
- // #############################
- const emailsSubscriptionChart = {
- data: {
- labels: [
- "Jan",
- "Feb",
- "Mar",
- "Apr",
- "Mai",
- "Jun",
- "Jul",
- "Aug",
- "Sep",
- "Oct",
- "Nov",
- "Dec"
- ],
- series: [[542, 443, 320, 780, 553, 453, 326, 434, 568, 610, 756, 895]]
- },
- options: {
- axisX: {
- showGrid: false
- },
- low: 0,
- high: 1000,
- chartPadding: {
- top: 0,
- right: 5,
- bottom: 0,
- left: 0
- }
- },
- responsiveOptions: [
- [
- "screen and (max-width: 640px)",
- {
- seriesBarDistance: 5,
- axisX: {
- labelInterpolationFnc: function(value) {
- return value[0];
- }
- }
- }
- ]
- ],
- animation: {
- draw: function(data) {
- if (data.type === "bar") {
- data.element.animate({
- opacity: {
- begin: (data.index + 1) * delays2,
- dur: durations2,
- from: 0,
- to: 1,
- easing: "ease"
- }
- });
- }
- }
- }
- };
- // ##############################
- // // // Completed Tasks
- // #############################
- const completedTasksChart = {
- data: {
- labels: ["12am", "3pm", "6pm", "9pm", "12pm", "3am", "6am", "9am"],
- series: [[230, 750, 450, 300, 280, 240, 200, 190]]
- },
- options: {
- lineSmooth: Chartist.Interpolation.cardinal({
- tension: 0
- }),
- low: 0,
- high: 1000, // creative tim: we recommend you to set the high sa the biggest value + something for a better look
- chartPadding: {
- top: 0,
- right: 0,
- bottom: 0,
- left: 0
- }
- },
- animation: {
- draw: function(data) {
- if (data.type === "line" || data.type === "area") {
- data.element.animate({
- d: {
- begin: 600,
- dur: 700,
- from: data.path
- .clone()
- .scale(1, 0)
- .translate(0, data.chartRect.height())
- .stringify(),
- to: data.path.clone().stringify(),
- easing: Chartist.Svg.Easing.easeOutQuint
- }
- });
- } else if (data.type === "point") {
- data.element.animate({
- opacity: {
- begin: (data.index + 1) * delays,
- dur: durations,
- from: 0,
- to: 1,
- easing: "ease"
- }
- });
- }
- }
- }
- };
- module.exports = {
- dailySalesChart,
- emailsSubscriptionChart,
- completedTasksChart
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement