SanAPI sample

author(s): 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>
    <p class="highcharts-description">
        Example how to use Highcharts with Santiment API. We are fetching Social Dominance and plot it.
    </p>
</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`
{
	getMetric(metric:"social_dominance_total") {
    timeseriesData(slug:"ethereum", from:"utc_now-180d", to:"utc_now", interval:"1d") {
      datetime
      value
    }
  }
}
`

let data = []

client.query({ query: QUERY}).then(result => {
  data = result.data.getMetric.timeseriesData.map(el => {
  	return [new Date(el.datetime).getTime(), el.value]
  })
	Highcharts.chart('container', {

    title: {
        text: 'SAN API using Highcharts'
    },

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

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

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

    series: [{
        name: 'Social Dominance',
        data: data
    }],

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

});
})