Created
November 11, 2019 19:53
-
-
Save odevodyssey/996eb81d9535b2d51e931bbf1b122455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const res = pm.response.json(); | |
// ----------------------------- | |
// - Structure data for charts - | |
// ----------------------------- | |
// EDIT THIS OBJECT TO BIND YOUR DATA | |
const vizData = { | |
symbol: res.symbol, | |
stockX: res.stock_exchange_short, | |
// Labels take an array of strings | |
labels: Object.keys(res.intraday), | |
// Data takes an array of numbers | |
data: _.map(Object.values(res.intraday), 'volume') | |
}; | |
var template = ` | |
<canvas id="myChart" height="150"></canvas> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script> | |
<script> | |
// Get DOM element to render the chart in | |
var ctx = document.getElementById("myChart"); | |
var timeFormat = 'YYYY-MM-DD HH:mm:ss'; | |
function newDate(days) { | |
return moment().add(days, 'd').toDate(); | |
} | |
function newDateString(days) { | |
return moment().add(days, 'd').format(timeFormat); | |
} | |
// Configure Chart JS here. | |
// You can customize the options passed to this constructor to | |
// make the chart look and behave the way you want | |
var myChart = new Chart(ctx, { | |
type: "line", | |
data: { | |
labels: [], // We will update this later in pm.getData() | |
datasets: [{ | |
label: '', | |
data: [], // We will update this later in pm.getData() | |
// Change these colours to customize the chart | |
backgroundColor: "#3e95cd", | |
borderColor: "#8e5ea2", | |
fill: false, | |
}] | |
}, | |
options: { | |
legend: { display: false }, | |
title: { | |
display: true, | |
text: '' | |
}, | |
scales: { | |
xAxes: [{ | |
type: 'time', | |
time: { | |
parser: timeFormat, | |
// round: 'day' | |
tooltipFormat: 'll HH:mm' | |
}, | |
scaleLabel: { | |
display: true, | |
labelString: 'Time' | |
} | |
}], | |
yAxes: [{ | |
display: true, | |
scaleLabel: { | |
display: true, | |
labelString: 'Shares' | |
} | |
}] | |
} | |
} | |
}); | |
// Access the data passed to pm.visualizer.set() from the JavaScript | |
// code of the Visualizer template | |
pm.getData(function (err, value) { | |
myChart.options.title.text = value.symbol + " on " + value.stockX | |
myChart.data.datasets[0].label = value.symbol + " Share Count" | |
myChart.data.datasets[0].data = value.data; | |
myChart.data.labels = value.labels; | |
myChart.update(); | |
}); | |
</script>`; | |
pm.visualizer.set(template, vizData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment