如何解决如何设置tradingview图表库图表自动更新?
我正在使用tradingview图表库建立一个显示图表的网站,并设法设置要从数据源显示的图表。但是,一旦加载图表,图表就不会自动更新或刷新,而无需重新加载网页。如何设置图表自动更新(例如间隔1m,5m等)?这是我使用的代码:
vertexShader() {
return `
varying vec2 vUv;
varying vec3 vPosition;
void main() {
vUv = uv;
vPosition = position;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
}
`
}
fragmentShader() {
return `
varying vec2 vUv;
varying vec3 vPosition;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float divider;
uniform float zoomFactor;
uniform bool hidden;
void main() {
float dividerWidth;
if (hidden) {
dividerWidth = 0.0;
} else {
dividerWidth = 0.03 / zoomFactor;
}
if (vPosition.x > divider + dividerWidth) {
gl_FragColor = texture2D(tex1,vUv);
} else if (vPosition.x < divider - dividerWidth) {
gl_FragColor = texture2D(tex0,vUv);
} else {
gl_FragColor = vec4(0.5,0.5,1.0,1.0);
}
}
`
}
提前感谢,感谢您的帮助。
解决方法
像这样创建名为 datafeed 的文件:
export default {
onReady: (callback) => {
console.log("[onReady]: Method call");
callback({});
},searchSymbols: (userInput,exchange,symbolType,onResultReadyCallback) => {
console.log("[searchSymbols]: Method call");
},resolveSymbol: (
symbolName,onSymbolResolvedCallback,onResolveErrorCallback
) => {
console.log("[resolveSymbol]: Method call",symbolName);
},getBars: async (
symbolInfo,resolution,from,to,onHistoryCallback,onErrorCallback,firstDataRequest
) => {
},subscribeBars: (
symbolInfo,onRealtimeCallback,subscribeUID,onResetCacheNeededCallback
) => {
console.log(
"[subscribeBars]: Method call with subscribeUID:",subscribeUID
);
},unsubscribeBars: (subscriberUID) => {
console.log(
"[unsubscribeBars]: Method call with subscriberUID:",subscriberUID
);
},};
并用数据馈送替换它:
import DATAFEED from './datafeed';
function initOnReady() {
var widget = window.tvWidget = new TradingView.widget({
// debug: true,// uncomment this line to see Library errors and warnings in the
fullscreen: true,symbol: 'AAPL',interval: '1D',container_id: "tv_chart_container",// BEWARE: no trailing slash is expected in feed URL
datafeed: DATAFEED,// ---> replace here
library_path: "charting_library/",locale: getParameterByName('lang') || "en",disabled_features: ["use_localstorage_for_settings"],enabled_features: ["study_templates"],charts_storage_url: 'https://saveload.tradingview.com',charts_storage_url: 'http://{$smarty.server.HTTP_HOST}',charts_storage_api_version: "1.1",client_id: 'tradingview.com',user_id: 'public_user_id',});
};
注意:交易视图本身根据需要管理大多数操作。
例如
如果您想拖动蜡烛图,交易视图计算视口并找出需要显示的蜡烛数量,然后调用 getBars
中的 datafeeds.js
方法。
查看示例: https://github.com/tradingview/charting-library-examples
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。