var graphcolors = ["C60C30","ff663f","ffc60d","5b8f22","006643","00b28f","363534","ff256c","e905aa","7d5bcb","e2e000"];
function graphurl(data){
	var coord=[], vertices=[], idx=0;
	for(var i=0;i<data.length;i++) {
		var n_words=data[i].n_words || 100;
		var list = data[i].progresses, today = new Date();
		var scores = [], pre_score = 0;
		today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
		for(var j=0;j<list.length;j++) {
			var m=list[j].played_at.match(/^(\d+)-(\d+)-(\d+)/);
			if (!m) continue;
			var played_at = new Date(m[1], m[2]-1, m[3]);
			var days = (today - played_at) / (86400 * 1000);
			if (days<16) {
				if (scores.length == 0) scores[ (pre_score>0)? 16:(days+1)]=pre_score;
				scores[days] = list[j].score;
			}
			pre_score =list[j].score;
		}
		var x_coord=[], y_coord=[];
		for(var j=16;j>=0;j--) {
			var s = scores[j];
			if (s!=undefined) {
				if (j<16) vertices.push( "d,"+graphcolors[idx]+","+idx+","+x_coord.length+",6.0" );
				x_coord.push( (16-j)*6 );
				s /= n_words;
				y_coord.push( (s>99)?99:(s<0)?0:Math.round(s) );
			}
		}
		if (x_coord.length>0) {
			if (!scores[0]) {
				x_coord.push( 16*6 );
				y_coord.push( y_coord[y_coord.length-1] );
			}
			coord.push( x_coord.join(',') );
			coord.push( y_coord.join(',') );
		} else {
			coord.push( '0' );
			coord.push( '0' );
		}
		idx++;
		if (idx>=6) break;
	}

	var url = "http://chart.apis.google.com/chart?chs=200x210&chf=c,lg,90,6E9FFB,1,C4D7FB,0|bg,s,FFFFFF";
	//url += "&cht=lxy&chxt=x,y&chxl=0:|2w|1w|Today|1:|0|"+(n_words*50)+"|"+(n_words*100);
	url += "&cht=lxy&chxt=x,y&chxl=0:|2w|1w|Today|1:|0|50%|100%";
	url += "&chd=t:"+ coord.join('|');
	url += "&chm="+ vertices.join('|');
	if (coord.length>0) url += "&chco="+ graphcolors.slice(0,coord.length).join(',');
	return url;
}
