	
	$dataname = $data
	$runname = $run_name
	$samplename = $sample_name

	for (j = 0; j < $dataname.length; j++){
		$dataname[j][0] = new Date($dataname[j][0])
	}
	for (j = 0; j < $runname.length; j++){
		for (i = 0; i < obj.length; i++){
			var ann = obj[i]
			if(ann.Run == $runname[j][0]){
				$runname[j][1]=ann.Annotation
			}else{}
		}
	}

	var $id_perSample = "$id_perSample_bool";

	$graphvar = new Dygraph(
		document.getElementById("$divname"),
		$dataname,	
		{
			labels: [ "Date","\xB12 Standard Deviation" , "Mean", "\xB12 Standard Deviation", "$ylabel"],
			labelsDiv: document.getElementById("$labeldiv"),
			labelsSeparateLines: true,
			legend: "always",
			title: '$title',
			xlabel: 'Date',
			ylabel: '$ylabel',
			showRangeSelector: true,
			rangeSelectorHeight: 20,
			rangeSelectorPlotFillColor: "rgba(0,0,0,0)",
			rangeSelectorPlotFillGradientColor: "rgba(0,0,0,0)",
			rangeSelectorPlotStrokeColor: "rgba(0,0,0,0)",
			highlightSeriesOpts: { highlightCircleSize : 5 },
			interactionModel: Dygraph.defaultInteractionModel,
			includeZero: true,	
			displayAnnotations: true,
			axisLabelFontSize: 10,
			titleHeight: 25,
			xLabelHeight: 15,
			yLabelWidth: 15,
			legendFormatter: legendFormatter,
			axes: {
				x: {	
					valueFormatter: function me(d,opt,se,dy,row,col) {
						var text = [], 
						data = $dataname[row],
						run = $runname[row],
						sample = $samplename[row];
						
						if($id_perSample ==  "True"){
							text = "<b> Sample ID: </b>".fontcolor("#000") + run[col] 
									+ "<br/><b> Run ID: </b>".fontcolor("#000") + "<font size='-1.5'>" + sample + "</font>" 
									+ "<br><b> Date:</b> ".fontcolor("#000") + moment(d).format("DD/MM/YYYY") 
									+ "<br/><b> Mean: </b>".fontcolor("#006400") + data[2]   
									+ "<br/><b> &plusmn;2 Standard Deviation: </b>".fontcolor("#ff0000") + data[1] + "-" + data[3]  
									+ "<br/><b> $ylabel: </b>".fontcolor("#0080ff") + data[4] + '</font>'
						}else{
							text = "<b>Run ID: </b>".fontcolor("#000") + run[col] 
									+ "<br/><b>Sample ID (y-value): </b>".fontcolor("#000") + "<font size='-1.5'>" + sample + "</font>" 
									+ "<br><b>Date:</b> ".fontcolor("#000") + moment(d).format("DD/MM/YYYY") 
									+ "<br/><b> Mean: </b>".fontcolor("#006400") + data[2]      
									+ "<br/><b> &plusmn;2 Standard Deviation: </b>".fontcolor("#ff0000") + data[1] + "-" + data[3]    
									+ "<br/><b> $ylabel: </b>".fontcolor("#0080ff") + data[4] + '</font>'
						}
						
						if (run[1].length != 0){
							note = "<br/><b>Notes: </b><br/>" + run[1] 
							text = 	text + note.fontcolor("red") 
							
						}
						
						return text	
					},
				},	
			},
			series: {
				"\xB12 Standard Deviation" : {
					strokePattern: Dygraph.DASHED_LINE ,
					color: "#ff0000",
					strokeWidth: 2,
				},
				"Mean" : {
					drawPoints: false,
					color: "#006400",
					strokeWidth: 2,
				},
				"$ylabel" : {
					drawPoints: true,
					color: "#0080ff",
					pointSize: 3,
					strokeWidth: 0,
				}
			},
			underlayCallback: function(canvas, area, g) {		
				
				ctx = g.hidden_ctx_;
				ctx.strokeStyle = "#dd4b39";
				
				for (i = 0; i < $dataname.length; i++) { 
								
					var point = $dataname[i][4],
					note = $runname[i][1],
					date = $dataname[i][0];
					
					if ($runname[i][0] == null){}
					else if(note.length != 0){
					
						mutated = g.toDomCoords(date, point)
						ctx.beginPath();
						ctx.arc(mutated[0], mutated[1],5,0,Math.PI*2,true);
						ctx.closePath();
						ctx.stroke();
					}
				}
				
				ctx.fillStyle = "#0080ff";
				ctx.strokeStyle = "#0080ff";
				var [bottom,top] = g.yAxisRange();
				for(i = 0; i < dateobj.length; i++) {
					date = dateobj[i];
					position = g.toDomCoords(date.Annotated_date,bottom);
					dateobj[i].key3 = position;
					canvas.fillText(dateobj[i].Notes,dateobj[i].key3[0]+2,dateobj[i].key3[1]-15);
					canvas.strokeRect(dateobj[i].key3[0],dateobj[i].key3[1]-25,dateobj[i].Notes.length*7,15)
					canvas.beginPath();
					canvas.moveTo(dateobj[i].key3[0],dateobj[i].key3[1]);
					canvas.lineTo(dateobj[i].key3[0],dateobj[i].key3[1]-10);
					canvas.closePath();
					canvas.stroke();
				}
			},
			pointClickCallback: function(e, point) {			
				run = $runname[point.idx][0]
				date = $dataname[point.idx][0]
				date =  moment(date).format("DD-MM-YYYY")
				//copyToClipboard(run)
				chartid = "$chart_id"
				makeQuery(run,date, chartid)
			},
		}
	);

	document.getElementById("$restorebutton").onclick 	= function() { restorePositioning($graphvar); };
	document.getElementById("$yearbutton").onclick 	= 	function() 	{$graphvar.updateOptions({dateWindow: [Date.parse('$startdate'),Date.parse('$enddate')]});};
	gs.push($graphvar);
	