Javascript tradingview轻型图表的日期仅显示1970年1月1日的错误日期
请帮我定制tradingview js图表。我对图表有一个严重的问题。 图表未显示从数据库拉入图表的准确日期 上图是显示所提供数据准确日期的图表 从数据库中提取的数据给出了错误的日期,从而给出了错误的图表。 如何更正图表日期Javascript tradingview轻型图表的日期仅显示1970年1月1日的错误日期,javascript,php,tradingview-api,lightweight-charts,Javascript,Php,Tradingview Api,Lightweight Charts,请帮我定制tradingview js图表。我对图表有一个严重的问题。 图表未显示从数据库拉入图表的准确日期 上图是显示所提供数据准确日期的图表 从数据库中提取的数据给出了错误的日期,从而给出了错误的图表。 如何更正图表日期 var investment_charts = LightweightCharts.createChart(document.getElementById('investment_charts'), { width: width,
var investment_charts = LightweightCharts.createChart(document.getElementById('investment_charts'), {
width: width,
height: height,
priceScale: {
scaleMargins: {
top: 0.2,
bottom: 0.2,
},
position: 'left',
borderVisible: true,
},
timeScale: {
borderVisible: false,
},
grid: {
horzLines: {
color: '#eee',
},
vertLines: {
color: '#ffffff',
},
},
crosshair: {
horzLine: {
visible: false,
labelVisible: false
},
vertLine: {
visible: true,
style: 0,
width: 1,
color: 'rgba(32, 38, 46, 0.1)',
labelVisible: false,
}
},
});
// chart.resize(320, 250);
var series = investment_charts.addAreaSeries({
topColor: 'rgba(0, 120, 255, 0.2)',
bottomColor: 'rgba(0, 120, 255, 0.0)',
lineColor: 'rgba(0, 120, 255, 1)',
lineWidth: 3
});
series.setData([
<?php
foreach($user->historychart as $key=>$value){
if($value->investment_amount != null){
echo '{ time:'.$value->created_at->format('Y-m-d').', value:'. $value->investment_amount.'},';
}
}
?>
]);
function businessDayToString(businessDay) {
return new Date(Date.UTC(businessDay.year, businessDay.month - 1, businessDay.day, 0, 0, 0)).toLocaleDateString();
}
var toolTipWidth = 96;
var toolTipHeight = 40;
var toolTipMargin = 15;
var priceScaleWidth = 10;
var toolTip = document.createElement('div');
toolTip.className = 'floating-tooltip-1';
document.getElementById('investment_charts').appendChild(toolTip);
// update tooltip
investment_charts.subscribeCrosshairMove(function(param) {
if (!param.time || param.point.x < 0 || param.point.x > width || param.point.y < 0 || param.point.y > height) {
toolTip.style.display = 'none';
return;
}
var dateStr = LightweightCharts.isBusinessDay(param.time)
? businessDayToString(param.time)
: new Date(param.time * 1000).toLocaleDateString();
toolTip.style.display = 'block';
var price = param.seriesPrices.get(series);
toolTip.innerHTML = '<div style="color: rgba(0, 120, 255, 0.9)">⬤ Naira</div>' +
'<div style="font-size: 24px; margin: 4px 0px; color: #20262E">' + (Math.round(price * 100) / 100).toFixed(2) + '</div>' +
'<div>' + dateStr + '</div>';
var left = param.point.x;
if (left > width - toolTipWidth - toolTipMargin) {
left = width - toolTipWidth;
} else if (left < toolTipWidth / 2) {
left = priceScaleWidth;
}
toolTip.style.left = left + 'px';
toolTip.style.top = 80 + 'px';
});
var charts = LightweightCharts.createChart(document.getElementById('charts'), {
width: width,
height: height,
priceScale: {
scaleMargins: {
top: 0.2,
bottom: 0.2,
},
position: 'left',
borderVisible: true,
},
timeScale: {
borderVisible: false,
},
grid: {
horzLines: {
color: '#eee',
},
vertLines: {
color: '#ffffff',
},
},
crosshair: {
horzLine: {
visible: false,
labelVisible: false
},
vertLine: {
visible: true,
style: 0,
width: 1,
color: 'rgba(32, 38, 46, 0.1)',
labelVisible: false,
}
},
});
// chart.resize(320, 250);
var seriesa = charts.addAreaSeries({
topColor: 'rgba(0, 120, 255, 0.2)',
bottomColor: 'rgba(0, 120, 255, 0.0)',
lineColor: 'rgba(0, 120, 255, 1)',
lineWidth: 3
});
seriesa.setData([
<?php
foreach($user->historychart as $key=>$value){
if($value->daily_profit != null){
echo '{ time:'.$value->created_at->format('Y-m-d').', value:'. $value->daily_profit.'},';
}
}
?>
]);
function businessDayToString1(businessDay) {
return new Date(Date.UTC(businessDay.year, businessDay.month - 1, businessDay.day, 0, 0, 0)).toLocaleDateString();
}
var toolTipWidth1 = 96;
var toolTipHeight1 = 40;
var toolTipMargin1 = 15;
var priceScaleWidth1 = 10;
var toolTip1 = document.createElement('div');
toolTip1.className = 'floating-tooltip-2';
document.getElementById('charts').appendChild(toolTip1);
// update tooltip
charts.subscribeCrosshairMove(function(param) {
if (!param.time || param.point.x < 0 || param.point.x > width || param.point.y < 0 || param.point.y > height) {
toolTip1.style.display = 'none';
return;
}
var dateStr = LightweightCharts.isBusinessDay(param.time)
? businessDayToString1(param.time)
: new Date(param.time * 1000).toLocaleDateString();
toolTip1.style.display = 'block';
var price = param.seriesPrices.get(seriesa);
toolTip1.innerHTML = '<div style="color: rgba(0, 120, 255, 0.9)">⬤ Naira</div>' +
'<div style="font-size: 24px; margin: 4px 0px; color: #20262E">' + (Math.round(price * 100) / 100).toFixed(2) + '</div>' +
'<div>' + dateStr + '</div>';
var left = param.point.x;
if (left > width - toolTipWidth1 - toolTipMargin1) {
left = width - toolTipWidth1;
} else if (left < toolTipWidth1 / 2) {
left = priceScaleWidth1;
}
toolTip1.style.left = left + 'px';
toolTip1.style.top = 80 + 'px';
});
var投资图表=LightweightCharts.createChart(document.getElementById(“投资图表”){
宽度:宽度,
高度:高度,,
价格等级:{
鳞片边缘:{
排名:0.2,
底部:0.2,
},
位置:'左',
没错,
},
时间尺度:{
边界可见:错误,
},
网格:{
霍兹林:{
颜色:“#eee”,
},
垂直线:{
颜色:“#ffffff”,
},
},
十字线:{
霍兹林:{
可见:假,
labelVisible:错误
},
垂直线:{
可见:对,
样式:0,
宽度:1,
颜色:“rgba(32,38,46,0.1)”,
labelVisible:错误,
}
},
});
//调整图表大小(320250);
var系列=投资图表。addAreaSeries({
topColor:“rgba(0,120,255,0.2)”,
底部颜色:“rgba(0,120,255,0.0)”,
线条颜色:“rgba(0、120、255、1)”,
线宽:3
});
series.setData([
]);
功能businessDayToString(businessDay){
返回新日期(Date.UTC(businessDay.year,businessDay.month-1,businessDay.day,0,0)).toLocaleDateString();
}
var-toolTipWidth=96;
var-toolTipHeight=40;
var-toolTipMargin=15;
var priceScaleWidth=10;
var toolTip=document.createElement('div');
toolTip.className='floating-toolTip-1';
document.getElementById(“投资图表”).appendChild(工具提示);
//更新工具提示
投资图表。subscribeCrosshairMove(函数(参数){
如果(!param.time | | param.point.x<0 | | param.point.x>宽度| | param.point.y<0 | | param.point.y>高度){
toolTip.style.display='none';
返回;
}
var dateStr=lightweightscharts.isBusinessDay(参数时间)
?businessDayToString(参数时间)
:新日期(param.time*1000).toLocaleDateString();
toolTip.style.display='block';
var价格=参数系列价格获取(系列);
toolTip.innerHTML=⬤ 奈拉+
“+(数学四舍五入(价格*100)/100)。固定(2)+”+
''+dateStr+'';
var left=参数点x;
如果(左>宽度-toolTipWidth-ToolTipArgin){
左=宽度-工具提示宽度;
}else if(左<工具提示宽度/2){
左=价格标度宽度;
}
toolTip.style.left=left+'px';
toolTip.style.top=80+‘px’;
});
var charts=LightweightCharts.createChart(document.getElementById('charts'){
宽度:宽度,
高度:高度,,
价格等级:{
鳞片边缘:{
排名:0.2,
底部:0.2,
},
位置:'左',
没错,
},
时间尺度:{
边界可见:错误,
},
网格:{
霍兹林:{
颜色:“#eee”,
},
垂直线:{
颜色:“#ffffff”,
},
},
十字线:{
霍兹林:{
可见:假,
labelVisible:错误
},
垂直线:{
可见:对,
样式:0,
宽度:1,
颜色:“rgba(32,38,46,0.1)”,
labelVisible:错误,
}
},
});
//调整图表大小(320250);
var seriesa=charts.addAreaSeries({
topColor:“rgba(0,120,255,0.2)”,
底部颜色:“rgba(0,120,255,0.0)”,
线条颜色:“rgba(0、120、255、1)”,
线宽:3
});
seriesa.setData([
]);
功能businessDayToString1(businessDay){
返回新日期(Date.UTC(businessDay.year,businessDay.month-1,businessDay.day,0,0)).toLocaleDateString();
}
变量toolTipWidth1=96;
var-toolTipHeight1=40;
变量1=15;
var priceScaleWidth1=10;
var toolTip1=document.createElement('div');
toolTip1.className='floating-tooltip-2';
document.getElementById('charts').appendChild(toolTip1);
//更新工具提示
图表。subscribeCrosshairMove(函数(参数){
如果(!param.time | | param.point.x<0 | | param.point.x>宽度| | param.point.y<0 | | param.point.y>高度){
toolTip1.style.display='none';
返回;
}
var dateStr=lightweightscharts.isBusinessDay(参数时间)
?businessDayToString1(参数时间)
:新日期(param.time*1000).toLocaleDateString();
toolTip1.style.display='block';
var价格=参数系列价格获取(系列);
toolTip1.innerHTML=⬤ 奈拉+
“+(数学四舍五入(价格*100)/100)。固定(2)+”+
''+dateStr+'';
var left=参数点x;
如果(左>宽度-工具提示宽度1-工具提示宽度1){
左=宽度-工具提示宽度1;
}否则如果(左<工具提示宽度1/2){
左=价格范围内的数字1;
}
toolTip1.style.left=左+'px';
toolTip1.style.top=80+‘px’;
});
我想问题的根源在于我调用了数据库中的数据循环,但我不知道为什么它显示了错误的日期
<?php
foreach($user->historychart as $key=>$value){
if($value->investment_amount != null){
echo '{ time:'.$value->created_at->format('Y-m-d').', value:'. $value->investment_amount.'},';
}
}
<
<?php
foreach($user->historychart as $key=>$value){
if($value->investment_amount != null){
echo '{ time:"'.$value->created_at->format('Y-m-d').'", value:'. $value->investment_amount.'},';
}
}
now = datetime.datetime.now()
timenow = str(now.strftime("%m/%d/%Y %H:%M:%S"))
date = datetime.datetime.strptime(timenow, "%m/%d/%Y %H:%M:%S")
timestamp = datetime.datetime.timestamp(date)
linechart = {
"time" : timestamp,
"value" : row[0]
}