const d = new Date();
let min = d.getMinutes();
function realtime () {
var interval = clearInterval(interval);
$.getJSON('https://anlikaltinfiyatlari.com/anlik/charts/jsonp2.php?filename=USDlive.json&islive=1&time='+min, function (data) {
$('[id=chart_]').highcharts('StockChart', {
chart: { panning: false, pinchType: 'null', marginTop: -5, borderWidth: 0, zoomType: 'null',plotBorderWidth: 1, plotBorderColor: '#cdcdcd',
events : {
load : function () {
var series = this.series[0];
var y;
var go = "USD";
/* A */
socket.on('update', function (dataj) {
var chart_data = JSON.parse(dataj);
if(go == "USD")
y = parseFloat(parseFloat(chart_data.USDTRY).toFixed(4));
if(go == "EUR")
y = parseFloat(parseFloat(chart_data.EURTRY).toFixed(4));
if(go == "GBP")
y = parseFloat(parseFloat(chart_data.GBPUSD*chart_data.USDTRY).toFixed(4));
if(go == "ons")
y = parseFloat(parseFloat(chart_data.XAUUSD).toFixed(4));
if(go == "gram")
y = parseFloat(parseFloat(chart_data.USDTRY*chart_data.XAUUSD/31.1).toFixed(4));
if(go == "ceyrek")
y = parseFloat(parseFloat(1.66*chart_data.USDTRY*chart_data.XAUUSD/31.1).toFixed(4));
});
var series = $('[id=chart_]').highcharts().series[0];
interval = setInterval(function () {
var x = (new Date()).getTime();
if(y != null && y != "" && !isNaN(parseFloat(y)))
{
series.addPoint([x, y], true, series.data.length >= 40);
}
}, 1000);
},
destroy: function () {
clearInterval(interval);
}
}
},
scrollbar : {
enabled : false, liveRedraw: true
},
tooltip:{valueDecimals:2,formatter:function(){var s=Highcharts.dateFormat('%H:%M:%S - %e %b %Y, %A',this.x);
$.each(this.points,function(){s+='
Fiyat = '+this.y.toFixed(4);+'';});return s;}},
navigator : {
enabled : false
},
title : {
text : 'DOLAR',
floating: true,
align: 'left',
x: 75,
y: 20
},
subtitle : {
text : 'ANLIK',
floating: true,
align: 'left',
x: 80,
y: 35 },
rangeSelector: {
buttons: [{
type: 'minute',
count: 1,
text: '1M'
}, {
type: 'minute',
count: 5,
text: '5M'
}, {
type: 'hour',
count: 1,
text: '1H'
}, {
type: 'day',
count: 1,
text: '1D'
}, {
type: 'week',
count: 1,
text: '1W'
}, {
type: 'all',
text: 'All'
}],
selected: 5
},
yAxis: [{
opposite: false,
showFirstLabel: true,
showLastLabel: true
}, {
opposite: true,
showFirstLabel: true,
showLastLabel: true,
linkedTo: 0
}],
series : [{
data : data, turboThreshold: 0
}] });
});
}
function live () {
$.getJSON('https://anlikaltinfiyatlari.com/anlik/charts/jsonp3.php?filename=USDlive.json&time='+min, function (data) {
// Find min and max values in the data
let minValue = Math.min(...data.map(point => point[1]));
let maxValue = Math.max(...data.map(point => point[1]));
// If all data points are the same, adjust the min and max values
if (minValue === maxValue) {
minValue *= 0.95; // Decrease minValue by 5%
maxValue *= 1.05; // Increase maxValue by 5%
}
$('[id=chart_]').highcharts('StockChart', {
chart: { panning: false, pinchType: 'null', marginTop: -20, borderWidth: 0, zoomType: 'null',plotBorderWidth: 1, plotBorderColor: '#ddd' },
scrollbar : {
enabled : false, liveRedraw: false
},
tooltip:{valueDecimals:2,formatter:function(){var s=Highcharts.dateFormat('%H:%M - %e %m %Y, %A',this.x);
$.each(this.points,function(){s+='
Fiyat = '+this.y.toFixed(4);+'';});return s;}},
navigator : {
enabled : false
},
title : {
text : 'Dolar/TL',
floating: true,
align: 'left',
x: 75,
y: 20
},
subtitle : {
text : 'Bugün',
floating: true,
align: 'left',
x: 80,
y: 35 },
rangeSelector: { selected:8},
yAxis: [{
opposite: false,
showFirstLabel: true,
showLastLabel: true, min: minValue, max: maxValue
}, {
opposite: true,
showFirstLabel: true,
showLastLabel: true,
linkedTo: 0, min: minValue, max: maxValue
}],
series : [{
data : data,
}] });
});
}
function chart (id, subtitle, selectedv)
{
$.getJSON('https://anlikaltinfiyatlari.com/anlik/charts/jsonp2.php?filename=USD-bdunya-katilim.json', function (data) {
$('[id='+id+']').highcharts('StockChart', {
chart: { panning: false, pinchType: 'null', marginTop: -20, borderWidth: 0, zoomType: 'null', plotBorderWidth: 1, plotBorderColor: '#ddd'},
scrollbar : {
enabled : false, liveRedraw: false
},
navigator : {
enabled : false
},
title : {
text : 'USD-bdunya-katilim',
floating: true,
align: 'left',
x: 75,
y: 20
},
subtitle : {
text : subtitle,
floating: true,
align: 'left',
x: 80,
y: 35 },
rangeSelector: { selected:selectedv},
yAxis: [{
opposite: false,
showFirstLabel: true,
showLastLabel: true
}, {
opposite: true,
showFirstLabel: true,
showLastLabel: true,
linkedTo: 0
}],
series : [{
data : data,
}] });
});
}