$(function() { var min = [], avg = []; min.push([gd(2020,09,24), 582.27, '']); avg.push([gd(2020,09,24), 582.27, '']); min.push([gd(2020,09,25), 583.92, '']); avg.push([gd(2020,09,25), 583.92, '']); min.push([gd(2020,09,26), 581.09, '']); avg.push([gd(2020,09,26), 581.09, '']); min.push([gd(2020,09,27), 581.09, '']); avg.push([gd(2020,09,27), 581.09, '']); min.push([gd(2020,09,28), 581.09, '']); avg.push([gd(2020,09,28), 581.09, '']); min.push([gd(2020,09,29), 577.31, '']); avg.push([gd(2020,09,29), 577.31, '']); Date.prototype.yyyymmdd = function() { var yyyy = this.getFullYear().toString(); var mm = (this.getMonth()+1).toString(); var dd = this.getDate().toString(); return yyyy + "." + (mm[1]?mm:"0"+mm[0]) + "." + (dd[1]?dd:"0"+dd[0]); } function gd(year, month, day) { return new Date(year, month - 1, day); } function eur_prefix(val, axis){ val = parseFloat(val); return parseFloat(val.toFixed(2)) + " €" } eur_prefix = function(val, axis){ val = parseFloat(val); return parseFloat(val.toFixed(2)) + " €" } var plot = $.plot("#flotchart", [ { data: avg, label: "средняя цена", points: { symbol: "circle", fillColor: "#767773"}}, { data: min, label: "минимальная цена", points: { symbol: "circle", fillColor: "#65a422"}} ], { colors: ["#767773", "#65a422"], series: { lines: { show: true }, points: { show: true, fill: true, lineWidth: 3 } }, grid: { hoverable: true, clickable: false, borderWidth: { top: 0.1, right: 0.1, left: 1, bottom: 1 }, }, yaxis: { min: 519, max: 643, tickFormatter: eur_prefix } , xaxis: { mode: "time", minTickSize: [4, "day"], timeformat:"%Y.%m.%d" } }); $("
").css({ position: "absolute", display: "none", border: "1px solid #65a422", padding: "3px", "background-color": "#efefef", opacity: 0.80 }).appendTo("body"); $("#flotchart").bind("plothover", function (event, pos, item) { if (item) { var x = item.datapoint[0], y = eur_prefix(item.datapoint[1].toFixed(2)); $("#tooltip").html(new Date(x).yyyymmdd() + " " + item.series.label + " " + y + " " + item.series.data[item.dataIndex][2]) .css({top: item.pageY+5, left: item.pageX+5}) .fadeIn(200); } else { $("#tooltip").hide(); } }); $("#flotgraph").show(); });