Octane, помогите пожалуйста объединить 2 скрипта.
Нужно, чтобы данные в массиве d заменялись на данные в подгружаемом txt.
1 читает txt (причем, как я понимаю по нажатию кнопки)
2 рисует график.
1 скрипт:
load_text('http://www.site.ru/data.txt');
var req;
function load_text(url) {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != undefined) {
req.onreadystatechange = function() {loadDone();};
req.open("GET", url, true);
req.send("");
} else {
alert("Can't load file");
}
}
function loadDone() {
if (req.readyState == 4) {
if (req.status == 200) {
alert("loaded:\n" + req.responseText);
} else {
alert("error:\n" + req.status + "\n" +req.statusText);
}
}
}
Второй:
<script id="source" language="javascript" type="text/javascript">
$(function () {
var d = [[-373597200000, 315.71], [-370918800000, 317.45], [-368326800000, 317.50], [-363056400000, 315.86], [-360378000000, 314.93], [-357699600000, 313.19], [-352429200000, 313.34], [-349837200000, 314.67], [-347158800000, 315.58], [-344480400000, 316.47], [-342061200000, 316.65], [-339382800000, 317.71], [-336790800000, 318.29], [-334112400000, 318.16], [-331520400000, 316.55], [-328842000000, 314.80], [-326163600000, 313.84], [-323571600000, 313.34], [-320893200000, 314.81], [-318301200000, 315.59], [-315622800000, 316.43], [-312944400000, 316.97], [1159653600000, 379.03], [1162335600000, 380.17], [1164927600000, 381.85], [1167606000000, 382.94], [1170284400000, 383.86], [1172703600000, 384.49], [1175378400000, 386.37], [1177970400000, 386.54], [1180648800000, 385.98], [1183240800000, 384.36], [1185919200000, 381.85], [1188597600000, 380.74], [1191189600000, 381.15], [1193871600000, 382.38], [1196463600000, 383.94], [1199142000000, 385.44]];
$.plot($("#placeholder"), [d], { xaxis: { mode: "time" } });
$("#whole").click(function () {
$.plot($("#placeholder"), [d], { xaxis: { mode: "time" } });
});
$("#nineties").click(function () {
$.plot($("#placeholder"), [d], { xaxis: {
mode: "time",
min: (new Date("1990/01/01")).getTime(),
max: (new Date("2000/01/01")).getTime()
} });
});
$("#ninetynine").click(function () {
$.plot($("#placeholder"), [d], { xaxis: {
mode: "time",
minTickSize: [1, "month"],
min: (new Date("1999/01/01")).getTime(),
max: (new Date("2000/01/01")).getTime()
} });
});
});
</script>
Содержимое txt:
[[-373597200000, 315.71], [-370918800000, 317.45], [-368326800000, 317.50], [-363056400000, 315.86], [-360378000000, 314.93], [-357699600000, 313.19], [-352429200000, 313.34], [-349837200000, 314.67], [-347158800000, 315.58], [-344480400000, 316.47], [-342061200000, 316.65], [-339382800000, 317.71], [-336790800000, 318.29], [-334112400000, 318.16], [-331520400000, 316.55], [-328842000000, 314.80], [-326163600000, 313.84], [-323571600000, 313.34], [-320893200000, 314.81], [-318301200000, 315.59], [-315622800000, 316.43]]
Не знаю нужны ли крайние квадратные скобки.