streaming data sample
Sample of how to stream volume data
by sonylnagale
HTML
<link rel="stylesheet" type="text/css" href="https://jsfiddle.chartiq.com/chart/css/stx-chart.css" media="screen" />
<div class="chartContainer" style="width:100%;height:400px;position:relative;"></div>
JavaScript
import { CIQ } from "https://jsfiddle.chartiq.com/chart/js/advanced.js";
import sampleData from "https://jsfiddle.chartiq.com/chart/examples/data/STX_SAMPLE_DAILY.js";
const stxx = new CIQ.ChartEngine({
container: document.querySelector(".chartContainer"),
layout: {
"chartType": "candle"
}
});
stxx.loadChart("SPY", sampleData);
// This is just dummy code for streaming quotes (randomly generated to update the last tick)
let cnt = 0;
let now;
setInterval(function() {
let newQuote = CIQ.clone(stxx.currentQuote());
let sdata = newQuote["Close"] + Math.round((Math.random() - .5) * 100) / 100;
if (cnt++ == 50) {
cnt = 0;
now = newQuote.DT.setDate(newQuote.DT.getDate() + 1);
} else {
now = newQuote.DT.setMinutes(newQuote.DT.getMinutes() + 1);
}
stxx.updateChartData({
Last: sdata,
Volume: 1000000,
Date: now
})
}, 500);