TradingView 初识
如引用 TradingView 库,需引入库中 3 个文件(所需库为 github 私有库,需申请)
<script type="text/javascript" src="/static/charting_library-master/charting_library/charting_library.min.js"></script>
<script type="text/javascript" src="/static/charting_library-master/datafeeds/udf/dist/polyfills.js"></script>
<script type="text/javascript" src="/static/charting_library-master/datafeeds/udf/dist/bundle.js"></script>
初始化图表:
TradingView.onready(function () {
var chart = window.tvWidget = new TradingView.widget({
symbol: 'd',
height: '900',
width: '1700',
interval: 'D',
toolbar_bg: '#c5c5c8',
timezone: 'Asia/Shanghai',
time_frames: [
{text: "1y", resolution: "1W"},
{text: "6m", resolution: "3D"},
{text: "3m", resolution: "1D"},
{text: "1m", resolution: "1D"},
{text: "1w", resolution: "30"},
{text: "3d", resolution: "30"},
{text: "1d", resolution: "30"},
{text: "6h", resolution: "15"},
{text: "1h", resolution: "1"},
{ text: "100y", resolution: "W", description: "All", title: "All" },
],
container_id: 'tv_chart_container',
library_path: '/static/charting_library-master/charting_library/',
locale: 'zh',
//datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com"),
datafeed: chart_data, //需要显示的数据内容
disabled_features:[
//'volume_force_overlay',// 成交量与k线分离
],
overrides:{
'volumePaneSize': 'small', //成交量高度设置,可选值 large, medium, small, tiny
}
});
我也不知道这是加载图表还是什么,反正就出现图表了
function createChartData(){
Datafeeds.Container = function () {
//this._configuration=configurationData
this._configuration = {
supports_search: false,
supports_group_request:false,
exchanges:[{value: 'DV', name: 'NYSE', desc: 'DeVry Education Group Inc.'}],
supported_resolutions: ['1', '15','D','M'],
supports_marks: false,
supports_time: false,
supports_timescale_marks: false,
symbols_types: [{name: 'Ny', value: 'dv'}],
}
}
Datafeeds.Container.prototype.onReady = function (callback) {
let that = this;
getChartData();
if(this._configuration){
setTimeout(function(){
callback(that._configuration);
}, 0);
}
}
Datafeeds.Container.prototype.getBars = function(symbolInfo, resolution, dataFrom, dataTo, onHistoryCallback) {
onHistoryCallback(dataBar);
}
Datafeeds.Container.prototype.resolveSymbol = function(symbolName, onSymbolResolvedCallback, onResolveErrorCallback) {
onSymbolResolvedCallback({
"name": 'D',
"timezone": "Asia/Shanghai",
"pricescale": 500,
"minmov": 1,
"ticker": 'D',
"description": "DIdontKnow",
"session": "24x7",
"type": "bitcoin",
"has_intraday": true,
"intraday_multipliers": ['1', '30', 'D'],
"has_weekly_and_monthly": false,
"has_no_volume": false,
"regular_session": "24x7"
});
}
return new Datafeeds.Container;
}
数据内容为自己设置的随机生成的一些数据,仅供测试使用
function getChartData() {
var time = 1528404420000;
var maxHigh = 8888;
var minLow = 8000;
for (var i =0; i<; i++){
var high = maxHigh - Math.floor(Math.random()*300);
var low = minLow + Math.floor(Math.random()*300);
var close = high - Math.floor(Math.random()*500);
var open = low + Math.floor(Math.random()*500);
var volume = parseInt(Math.random()*100);
this.dataBar.push({
time:time,
close:close,
open:open,
high:high,
low:low,
volume:volume
})
time += 2000000;
}
//console.log(dataBar);
}
整体代码:
<!-- TradingView Widget BEGIN -->
<html>
<head>
<script type="text/javascript" src="/static/charting_library-master/charting_library/charting_library.min.js"></script>
<script type="text/javascript" src="/static/charting_library-master/datafeeds/udf/dist/polyfills.js"></script>
<script type="text/javascript" src="/static/charting_library-master/datafeeds/udf/dist/bundle.js"></script>
</head> <body>
<div id="tv_chart_container"></div> </body>
<script type="text/javascript">
var dataBar = [];
var chart_data = createChartData();
TradingView.onready(function () {
var chart = window.tvWidget = new TradingView.widget({
symbol: 'd',
height: '900',
width: '1700',
interval: 'D',
toolbar_bg: '#c5c5c8',
timezone: 'Asia/Shanghai',
time_frames: [
{text: "1y", resolution: "1W"},
{text: "6m", resolution: "3D"},
{text: "3m", resolution: "1D"},
{text: "1m", resolution: "1D"},
{text: "1w", resolution: "30"},
{text: "3d", resolution: "30"},
{text: "1d", resolution: "30"},
{text: "6h", resolution: "15"},
{text: "1h", resolution: "1"},
{ text: "100y", resolution: "W", description: "All", title: "All" },
],
container_id: 'tv_chart_container',
library_path: '/static/charting_library-master/charting_library/',
locale: 'zh',
//datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com"),
datafeed: chart_data,
disabled_features:[
//'volume_force_overlay',// 成交量与k线分离
],
overrides:{
'volumePaneSize': 'small', //成交量高度设置,可选值 large, medium, small, tiny }
});
chart.onChartReady(function () {
//chart.chart().createStudy('MA Cross', false, false); // K线图添加初始化曲线
}) ;
});
function createChartData(){
Datafeeds.Container = function () {
//this._configuration=configurationData
this._configuration = {
supports_search: false,
supports_group_request:false,
exchanges:[{value: 'DV', name: 'NYSE', desc: 'DeVry Education Group Inc.'}],
supported_resolutions: ['1', '15','D','M'],
supports_marks: false,
supports_time: false,
supports_timescale_marks: false,
symbols_types: [{name: 'Ny', value: 'dv'}],
}
}
Datafeeds.Container.prototype.onReady = function (callback) {
let that = this;
getChartData();
if(this._configuration){
setTimeout(function(){
callback(that._configuration);
}, 0);
}
} Datafeeds.Container.prototype.getBars = function(symbolInfo, resolution, dataFrom, dataTo, onHistoryCallback) {
onHistoryCallback(dataBar); }
Datafeeds.Container.prototype.resolveSymbol = function(symbolName, onSymbolResolvedCallback, onResolveErrorCallback) {
onSymbolResolvedCallback({
"name": 'D',
"timezone": "Asia/Shanghai",
"pricescale": 500,
"minmov": 1,
"ticker": 'D',
"description": "DIdontKnow",
"session": "24x7",
"type": "bitcoin",
"has_intraday": true,
"intraday_multipliers": ['1', '30', 'D'],
"has_weekly_and_monthly": false,
"has_no_volume": false,
"regular_session": "24x7"
});
} return new Datafeeds.Container;
}
function getChartData() {
var time = 1528404420000;
var maxHigh = 8888;
var minLow = 8000;
for (var i =0; i<10000; i++){
var high = maxHigh - Math.floor(Math.random()*300);
var low = minLow + Math.floor(Math.random()*300);
var close = high - Math.floor(Math.random()*500);
var open = low + Math.floor(Math.random()*500);
var volume = parseInt(Math.random()*100);
this.dataBar.push({
time:time,
close:close,
open:open,
high:high,
low:low,
volume:volume
})
time += 2000000;
}
//console.log(dataBar);
}
</script>
<p>chart</p>
</html>
TradingView
效果图:

TradingView 初识的更多相关文章
- Android动画效果之初识Property Animation(属性动画)
前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...
- 初识Hadoop
第一部分: 初识Hadoop 一. 谁说大象不能跳舞 业务数据越来越多,用关系型数据库来存储和处理数据越来越感觉吃力,一个查询或者一个导出,要执行很长 ...
- python学习笔记(基础四:模块初识、pyc和PyCodeObject是什么)
一.模块初识(一) 模块,也叫库.库有标准库第三方库. 注意事项:文件名不能和导入的模块名相同 1. sys模块 import sys print(sys.path) #打印环境变量 print(sy ...
- 初识IOS,Label控件的应用。
初识IOS,Label控件的应用. // // ViewController.m // Gua.test // // Created by 郭美男 on 16/5/31. // Copyright © ...
- UI篇(初识君面)
我们的APP要想吸引用户,就要把UI(脸蛋)搞漂亮一点.毕竟好的外貌是增进人际关系的第一步,我们程序员看到一个APP时,第一眼就是看这个软件的功能,不去关心界面是否漂亮,看到好的程序会说"我 ...
- Python导出Excel为Lua/Json/Xml实例教程(一):初识Python
Python导出Excel为Lua/Json/Xml实例教程(一):初识Python 相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出 ...
- 初识SpringMvc
初识SpringMvc springMvc简介:SpringMVC也叫Spring Web mvc,属于表现层的框架.Spring MVC是Spring框架的一部分,是在Spring3.0后发布的 s ...
- 初识redis数据类型
初识redis数据类型 1.String(字符串) string是redis最基本的类型,一个key对应一个value. string类型是二进制安全的.意思是redis的string可以包含任何数据 ...
- Redis初识、设计思想与一些学习资源推荐
一.Redis简介 1.什么是Redis Redis 是一个开源的使用ANSI C 语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value 数据库,并提供多种语言的API.从2010 年 ...
随机推荐
- SELECT INTO 和 INSERT INTO SELECT比较
Insert是T-sql中常用语句,但我们在开发中经常会遇到需要表复制的情况,如将一个table1的数据的部分字段复制到table2中,或者将整个table1复制到table2中,这时候我们就要使用S ...
- C++ Rule of Three
Rule of Three The rule of three (also known as the Law of The Big Three or The Big Three) is a rule ...
- 20155231 2016-2017-2 《Java程序设计》第8周学习总结
20155231 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 学习目标 了解NIO 会使用Channel.Buffer与NIO2 会使用日志API.国际化 ...
- Android笔记之开机自启
有时候需要应用具有开机自启的能力,或者更常见的场景是开机时悄悄在后台启动一个Service. 关键点: 1. Android系统在开机的时候会发送一条广播消息,只需要接收这条广播消息即可,不过需要注意 ...
- Python练习-函数版-锁定三次登陆失败的用户
代码如下: # 编辑者:闫龙 if __name__ == '__main__': import UserLoginFuncation LoclCount=[]; while True: UserNa ...
- 【codeforces】【比赛题解】#864 CF Round #436 (Div.2)
做出了4题,还不错,可惜还是掉rating……能保持在蓝名已经不错了. 题目跳转链接. [A]公平的游戏 题意: Petya和Vasya在玩游戏.他们有n张卡片(n是偶数).每张卡片上有一个整数. 游 ...
- Linux下内存泄漏工具
概述 内存泄漏(memory leak)指由于疏忽或错误造成程序未能释放已经不再使用的内存的情况,在大型的.复杂的应用程序中,内存泄漏是常见的问题.当以前分配的一片内存不再需要使用或无法访问时,但是却 ...
- Centos 软连接和硬链接
1.软链接: 建立软链接:ln -s /usr/local/node-v4.2.6-linux-x86/bin/node /usr/local/bin/node 解释:将/usr/local/node ...
- InnoDB锁问题
InnoDB锁问题 InnoDB与MyISAM的最大不同有两点:一是支持事务(TRANSACTION):二是采用了行级锁.行级锁与表级锁本来就有许多不同之处,另外,事务的引入也带来了一些新问题.下面我 ...
- git —— pycharm+git管理/编辑项目
pycharm+git 管理/编辑项目 一.pycharm中配置github 二.配置git 并不是配置了GitHub就可以的.还需要配置一下Git 前提是本地中已经安装了git 三.把本地项目上传 ...