ビットコインのリアルタイムデータをチャートに追加しました。トレーディングビューでさえ処理できない高さのピークがありました... 少なくとも、私のチャートでは。
ご覧のとおり、6 月 2 日にビットコインが高騰し、画面からはみ出しました。
実際の TradingView ページ自体ではすべて正常に表示されるため、これは修正可能であるはずです:
また、チャートをズームアウトすると、完全に正常に表示されます:
だから私が望むのは、私のチャートが、tradingview.com と同じようにスケーリングされることです。 .
これは私のコードです:
// Predifined variables
var chart, priceArea, fetchedData;
// Faster to write log();
const log = console.log;
// Get data.
fetch('./getData.php', {
method: 'GET'
}).then(response => response.json()).then(function (data) {
// Set data to a global variable for global usage.
fetchedData = data;
// To make sure the chart is initialized and set after this fetch is done. Else I would get a error for setting data that I do not yet have.
initChartSettings();
});
/**
* Initializes the chart and its settings.
*/
function initChartSettings() {
// Create chart canvas
chart = LightweightCharts.createChart(document.getElementById('Chart'), {width: 1500, height: 700,});
// Could also be done in the width and height code line but thought it might work for scaling.
chart.applyOptions({
timeScale: {
// Adds hours and minutes to the chart.
timeVisible: true,
secondsVisible: false
}
});
// Init price line
priceArea = chart.addAreaSeries();
// This array is needed to make the setData work. It expects an array with objects.
let arrayWithOldData = [];
// Get each item in the fetchedData array. Since it gives more data then I need I use this for loop to take the time and value. Used to create chart lines.
for (let i = 0; i < fetchedData.length; i++) {
let dataElement = fetchedData[i];
// Object needed for the arrayWithOldData.
let oldData = {
// Timestamp / 1000 to make it a workable timestamp for tradingview chart and + 7200 seconds to make sure I get a timestamp of amsterdam (+2:00).
time: (dataElement[0] / 1000) + 7200,
value: dataElement[4]
};
// Add the data to the array.
arrayWithOldData.push(oldData);
}
log(arrayWithOldData);
// Set data
priceArea.setData(arrayWithOldData);
// PriceLine options
priceArea.applyOptions({
topColor: 'rgba(70, 130, 180, 0.5)',
bottomColor: 'rgba(70, 130, 180, 0.1)',
lineColor: '#4682B4',
lineWidth: 2
});
startTime = new Date();
updateLiveChartData();
}
私が試したこと:
コードで次のことを試しました: https://github.com/tradingview/lightweight-charts/blob/master/docs/customization.md -> 価格軸 -> priceScale() -> autoScale: true と異なるスケールのマージントップとボトムス。scaleMarginsは機能しているようですが、時間を遡ってピークが見えなくなったことを確認すると、すべてがフラットと同じくらい良いです:(コードの最後に入れようとしました: chart.timeScale().fitContent() ; しかし、これは私が今持っている方法と同じ結果をもたらしますが、ズームアウトします. timeScale でズームインしても、同じように見えます.