ETH Spent over time

author(s): Yura Zatsepin

by Zatcepin

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<!-- Include the library in the page -->
<script src="https://unpkg.com/[email protected]"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
</figure>

CSS

.highcharts-figure, .highcharts-data-table table {
    min-width: 360px; 
    max-width: 800px;
    margin: 1em auto;
}

.highcharts-data-table table {
	font-family: Verdana, sans-serif;
	border-collapse: collapse;
	border: 1px solid #EBEBEB;
	margin: 10px auto;
	text-align: center;
	width: 100%;
	max-width: 500px;
}
.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}
.highcharts-data-table th {
	font-weight: 600;
    padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
    padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}
.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

JavaScript

const client = new Apollo.lib.ApolloClient({
  networkInterface: Apollo.lib.createNetworkInterface({
    uri: 'https://api.santiment.net/graphql',
    transportBatching: true,
  }),
  connectToDevTools: true,
})

const QUERY = Apollo.gql`
{
	ethSpentOverTimeByErc20Projects(from:"2019-01-01T00:00:00Z", to:"2020-04-01T00:00:00Z", interval:"1d") {
      datetime
      ethSpent
    }
}
`

data = []

client.query({ query: QUERY}).then(result => {

  data = result.data.ethSpentOverTimeByErc20Projects.map(el => {
  	
  	return [new Date(el.datetime).getTime(), el.ethSpent]
  })
  console.log(data)
	Highcharts.chart('container', {

    title: {
        text: 'ETH SPENT OVERY TIME FOR ERC20 PROJECTS'
    },

    subtitle: {
        text: 'Made by Zatcepin with love'
    },

    yAxis: {
        title: {
            text: 'ETH'
        }
    },
    xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: {
           day: '%b %Y'    //ex- 01 Jan 2016
        }
},

    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    series: [{
        name: 'ETH',
        data: data
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
})