/* This set of functions can create mortality, survival, bar, pie, and pictograms representing cancer death rates over a 15 year-period following diagnosis. */  
	
/*Called at page load--loads a mortality graph of all zeros.  If outcomeOrTherapy is a string "therapy", the graph will include additional plots for therapy impact.	*/
function Loaded_Chart(graph_type){		                     								
			plotGraph(new Array([0],[0],[0],[0],[0],[0]), "death", 0, graph_type == "therapy", 0);			
	}
	
/*generates a graph of the given type.  datapoints is either a 3x15 or 6x15 (if includeTherapy is true) array of values between zero and one, with each row representing, in order, 
(0) chance of cancer death in each of 15 years
(1) chance of non-cancer death ...
(2)	overall chance of death ...
(3) chance of cancer death with therapy
(4) chance of non-cancer death with therapy
(5) overall chance of death with therapy  */

function plotGraph(datapoints, graph_type, yearToGraph, includeTherapy, endYear) {
 
    if (datapoints == null) {  // If no points are provided, use the saved set of datapoints
        datapoints = plotGraph.dpoints; 
    }  else {   //save the points to a function-level variable 
        plotGraph.dpoints = datapoints; 
    }
    
    if (graph_type == null) {  // If no type is provided, use the saved type
        graph_type = plotGraph.g_type; 
    }  else {   //save the type to a function-level variable 
        plotGraph.g_type = graph_type; 
    } 
    

	if (endYear  == null) {  // If no endYear is provided, use the saved type	 	
        endYear = plotGraph.endY; 
    }  else {   //save the type to a function-level variable 
        plotGraph.endY = endYear; 
    }   

    if (yearToGraph == null) { // If no year is provided, use the saved year
       yearToGraph = plotGraph.yearTG; 
    }  else {   //check the value is not out of bounds, and save the type to a function-level variable 
        yearToGraph = Math.min(endYear,  yearToGraph);
        yearToGraph = Math.max(0,  yearToGraph); 
        plotGraph.yearTG = yearToGraph; 
    }  
    
    if (includeTherapy == null) {  // If no type is provided, use the saved type
        includeTherapy = plotGraph.incTherapy; 
    }  else {   //save the type to a function-level variable 
        plotGraph.incTherapy = includeTherapy; 
    }   
    
    
         
    if (graph_type=="death" || graph_type=="survival") { 							
    	plotLineGraph(datapoints, graph_type, includeTherapy, endYear);        	
    } else if (graph_type=="pie") { 		
    	plotPieGraph(datapoints, graph_type, yearToGraph, includeTherapy, endYear);      	
    } else if ( graph_type=="pictogram") { 					
        plotPictogram(datapoints, graph_type, yearToGraph, includeTherapy, endYear);		
    } else if (graph_type=="bar") {
        plotBarGraph(datapoints,  graph_type, yearToGraph, includeTherapy, endYear);
    }			
}

	
function plotLineGraph(datapoints, graph_type, includeTherapy, endYear) {
    outcomeLineNames = ["Cancer", "Non-cancer", "Overall"];
    therapyLineNames = ["Cancer (w/therapy)", "Cancer", "Non-cancer", "Overall (w/therapy)", "Overall"];
    
    
    if (!includeTherapy) {
        lineNames = outcomeLineNames; 
        lineIndex = [0,1,2];                 
    } else    {
        lineNames = therapyLineNames; 
        lineIndex = [3,0,4,5,2];                            
    }    
	chart_type = "<chart_type>line</chart_type>";
	deathType = true;
	
    if (graph_type =="survival") {
        deathType = false; 
    }
    
        						
	chart_data = "<chart_data>";
	
	chart_data = chart_data+"<row>";
	chart_data = chart_data+"<null/>";
	numDataPoints = datapoints[1].length;
	plot_month_interval = endYear * 12 / (numDataPoints-1);
	for(i=0;i<numDataPoints ;i++) {	
		if ((i*plot_month_interval) % 12 == 0) { 
			chart_data = chart_data+"<string>"+((i*plot_month_interval)/12)+"</string>";
		} else {
			chart_data = chart_data+"<string></string>";
		}
	}
	chart_data = chart_data+"</row>";
	
	for (k=0; k<lineNames.length; k++)      {         	
		chart_data = chart_data+"<row>";
		chart_data = chart_data+"<string>" + lineNames[k] + "</string>";
		for(i=0;i<numDataPoints ;i++) {		    
            if (deathType) {
		       chart_data = chart_data+"<number>"+ datapoints[lineIndex[k]][i] * 100 +"</number>";
            } else {
	           chart_data = chart_data+"<number>"+ (1-datapoints[lineIndex[k]][i]) * 100 +"</number>";}
        }		
		chart_data = chart_data+"</row>";
	}
	
	chart_data = chart_data+"</chart_data>";
	
	chart_style = "<chart_rect x='30' y='5' width='" + ((total_width *1) -40) + "' height='" + ((total_height*1) -35) + "' />";	
	
	chart_style = chart_style + "<chart_border top_thickness='0' bottom_thickness='1' left_thickness='1' right_thickness='0' color='777777' />";		
	chart_style = chart_style+"<chart_pref line_thickness='1.5' point_shape='circle' fill_shape='true' />";
	if (graph_type=="death") {
		chart_style = chart_style+"<legend x='35' y='52' width='0' height='0' margin='5' fill_color='000000' fill_alpha='10' line_color='000000' line_alpha='0' line_thickness='0' bullet='circle' size='11' color='000000' alpha='60' />";
	} else if (graph_type=="survival") {
		chart_style = chart_style+"<legend x='35' y='" + ((total_height*1) -129) + "' width='0' height='0' margin='5' fill_color='000000' fill_alpha='10' line_color='000000' line_alpha='0' line_thickness='0' bullet='circle' size='11' color='000000' alpha='60' />";
	}
	chart_style = chart_style+"<chart_guide horizontal='true' vertical='true' thickness='1' alpha='25' type='dashed' snap_h='true' snap_v='true' radius='6' fill_color='000000' fill_alpha='25' text_h_alpha='0' text_v_alpha='0' text_color='000000' />";
	chart_style = chart_style+"<chart_label position='cursor' suffix='%' size='12' color='000000' alpha='50' />";
	chart_style = chart_style+"<chart_transition type='slide_right' delay='0.5' duration='0.5' order='series' />";
	chart_style = chart_style+"<axis_value min='0' max='100' mode='trim' suffix='%' size='10' color='000000' alpha='65' steps='5' />";
	chart_style = chart_style+"<axis_category size='10' color='000000' alpha='65' />";
	chart_style = chart_style+"<axis_ticks category_ticks='true' major_thickness='2' major_color='aaaaaa' />";   		
	
	chart_draw = "<draw>";
	if (graph_type=="death") {
		chart_draw = chart_draw+"<text alpha='30' size='36' x='31' y='0' width='300' height='36' h_align='left' v_align='top'>mortality risk</text>";
		chart_draw = chart_draw+"<image url='/cancer/i/full_screen.swf' x='315' y='5' width='20' height='15' />";
	chart_draw = chart_draw+"<text alpha='65' size='10' x='300' y='20' width='60' height='15' h_align='left' v_align='middle'>enlarge</text>";
	} else if (graph_type=="survival") {
		chart_draw = chart_draw+"<text alpha='30' size='36' x='31' y='" + ((total_height*1) -68) + "' width='300' height='36' h_align='left' v_align='top'>survival</text>";
		chart_draw = chart_draw+"<image url='/cancer/i/full_screen.swf' x='315' y='" + ((total_height*1) -48) + "' width='20' height='15' />";
	    chart_draw = chart_draw+"<text alpha='65' size='10' x='275' y='" + ((total_height*1) -48) + "' width='60' height='15' h_align='left' v_align='middle'>enlarge</text>";
	}
	chart_draw = chart_draw+"<text alpha='65' size='10' x='39' y='" + ((total_height*1) -15) + "' width='300' height='75' h_align='center' v_align='top'>Year after diagnosis</text>";
	
	chart_draw = chart_draw+"</draw>";
	
	if (!includeTherapy)	{	      
		series_style = "<series_color><color>E87D7D</color><color>F0CB75</color><color>5970A6</color></series_color>";
        series_style = series_style+"<series_explode><number>100</number><number>100</number><number>150</number></series_explode>";
    } else {
         series_style = "<series_color><color>804140</color><color>E87D7D</color><color>F0CB75</color><color>404F80</color><color>5970A6</color></series_color>";
        series_style = series_style+"<series_explode><number>100</number><number>100</number><number>100</number><number>150</number><number>150</number></series_explode>";
    }
    
	chart_links = "<link>";
        if (graph_type=="death") {
             chart_links = chart_links+"<area x='315' y='5' width='20' height='15' target='toggle_fullscreen' />";
        } else {
             chart_links = chart_links+"<area x='315' y='" + ((total_height*1) -48) + "' width='20' height='15' target='toggle_fullscreen' />";
        }
	chart_links = chart_links+"</link>";
		
	document.my_chart_1.Update_XML("<chart>"+"<license>LTAHVA4JESMO9UJ5CWK-2XOI1X0-7L</license>"+chart_type+chart_data+chart_style+series_style+chart_draw+chart_links+"</chart>", true, "reset"); 
} 


function plotPieGraph(datapoints,graph_type, yearToGraph, includeTherapy, endYear)    {
    //The following function plots the data
    numDataPoints = datapoints[1].length;
	plot_month_interval = endYear * 12 / (numDataPoints-1);
	yearToGraphIndex = yearToGraph * 12 / plot_month_interval; 
	
    chart_type = "<chart_type>pie</chart_type>";
    
    chart_data = "<chart_data>";
    chart_data = chart_data+"<row>";
    chart_data = chart_data+"<null/>";
    if (!includeTherapy)  {
        chart_data = chart_data+"<string>Cancer Death</string><string>Non-cancer death</string><string>Alive</string>";
    }   else {
        chart_data = chart_data+"<string>Cancer Death</string><string>Non-cancer death</string><string>Alive</string><string>Add'l alive w/ therapy</string>";     
    }    
    chart_data = chart_data+"</row>";
    
    chart_data = chart_data+"<row>";
    chart_data = chart_data+"<string></string>";
    if (!includeTherapy)   {              
        chart_data = chart_data+"<number>"+Math.round(datapoints[0][yearToGraphIndex ]*100)+"</number>";
        chart_data = chart_data+"<number>"+Math.round(datapoints[1][yearToGraphIndex ]*100)+"</number>";
        chart_data = chart_data+"<number>"+(100-Math.round(datapoints[0][yearToGraphIndex ]*100)-Math.round(datapoints[1][yearToGraphIndex ]*100))+"</number>";

    } else{
        chart_data = chart_data+"<number>"+Math.round(datapoints[3][yearToGraphIndex ]*100)+"</number>";
      chart_data = chart_data+"<number>"+Math.round(datapoints[4][yearToGraphIndex ]*100)+"</number>";
      chart_data = chart_data+"<number>"+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex ]*100))+"</number>";
      chart_data = chart_data+"<number>"+(100-(100-Math.round(datapoints[0][yearToGraphIndex ]*100)-Math.round(datapoints[1][yearToGraphIndex ]*100)) - Math.round(datapoints[3][yearToGraphIndex ]*100) - Math.round(datapoints[4][yearToGraphIndex ]*100))+"</number>";
        
    }      
    chart_data = chart_data+"</row>";
    chart_data = chart_data+"</chart_data>";
    chart_style = "<chart_rect x='30' y='10' width='" + ((total_width *1) -170) + "' height='" + ((total_height*1) -65) + "' />";	
	chart_style = chart_style+"<chart_pref line_thickness='1.5' point_shape='circle' fill_shape='true' />";
	chart_style = chart_style+"<legend layout='horizontal' x='35' y='" + ((total_height*1) -55) + "' width='" + ((total_width *1) -70) + "' height='40' margin='5' fill_color='000000' fill_alpha='0' line_color='000000' line_alpha='0' line_thickness='0' bullet='square' size='11' color='000000' alpha='60' />";
	chart_style = chart_style+"<chart_label position='cursor' suffix='%' size='12' color='000000' alpha='50' />";
	chart_style = chart_style+"<chart_transition type='scale' delay='0.5' duration='0.5' order='series' />";
	chart_style = chart_style+"<axis_value min='0' max='100' suffix='%' size='10' color='000000' alpha='65' steps='5' />";
    
    if (!includeTherapy)	{   	      
       series_style = "<series_color><color>E87D7D</color><color>F0CB75</color><color>99BF60</color></series_color>";
    }else {
        series_style = "<series_color><color>E87D7D</color><color>F0CB75</color><color>99BF60</color><color>408040</color></series_color>"; }
    
    chart_draw = "<draw>";
    chart_draw = chart_draw+"<text size='16' x='235' y='35' width='100' height='20'>Year: "+yearToGraph+"</text>";
    chart_draw = chart_draw+"<text size='10' x='220' y='55' width='120' height='20'>Click to change year:</text>";
    chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/minus.swf' x='250' y='75' width='15' height='15' />";
    chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/plus.swf' x='270' y='75' width='15' height='15' />";
    if (!includeTherapy) {
        chart_draw = chart_draw+"<text size='10' x='210' y='105' width='150' height='230'>In a group of 100 people\rwith similar characteristics,\r"+Math.round(datapoints[0][yearToGraphIndex ]*100)+" will have died from cancer\rby year "+yearToGraph+", "+Math.round(datapoints[1][yearToGraphIndex ]*100)+" will have died\rfrom causes other than\rcancer, and "+(100-Math.round(datapoints[0][yearToGraphIndex ]*100)-Math.round(datapoints[1][yearToGraphIndex ]*100))+" will still be\ralive."+"</text>";
    } else {
        chart_draw = chart_draw+"<text size='10' x='210' y='105' width='150' height='230'>By year "+yearToGraph+", in a group of 100\rsimilar people:\r  "+Math.round(datapoints[4][yearToGraphIndex ]*100)+" people will have died of\rnon-cancer causes,\r  "+Math.round(datapoints[3][yearToGraphIndex ]*100)+" will have died of cancer,\r  "+(100-Math.round(datapoints[0][yearToGraphIndex ]*100)-Math.round(datapoints[1][yearToGraphIndex ]*100))+" will still be alive.\r\rWith therapy, "+(100-Math.round(datapoints[4][yearToGraphIndex ]*100)-Math.round(datapoints[3][yearToGraphIndex ]*100))+" will still\r be alive.</text>";}
    
    chart_draw = chart_draw+"<image url='/cancer/i/full_screen.swf' x='305' y='5' width='20' height='15' />";
	chart_draw = chart_draw+"<text alpha='65' size='10' x='265' y='5' width='60' height='15' h_align='left' v_align='middle'>enlarge</text>";
    chart_draw = chart_draw+"</draw>";
    
    chart_links = "<link>";
    
    chart_links = chart_links+"<area x='250' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph -1) + ")' />";
    chart_links = chart_links+"<area x='270' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph +1) + ")' />";
    chart_links = chart_links+"<area x='305' y='5' width='20' height='15' target='toggle_fullscreen' />";
    chart_links = chart_links+"</link>";
    
    chart_filter = "<filter>";
    chart_filter = chart_filter+"<shadow id='low' distance='2' angle='45' alpha='50' blurX='5' blurY='5' />";
    chart_filter = chart_filter+"</filter>";

    document.my_chart_1.Update_XML("<chart>"+"<license>LTAHVA4JESMO9UJ5CWK-2XOI1X0-7L</license>"+chart_type+chart_data+chart_style+series_style+chart_draw+chart_links+chart_filter+"</chart>", true, "reset");      
}


function plotPictogram(datapoints, graph_type, yearToGraph, includeTherapy, endYear) {
	 numDataPoints = datapoints[1].length;
	plot_month_interval = endYear * 12 / (numDataPoints-1);
	yearToGraphIndex = yearToGraph * 12 / plot_month_interval; 


    chart_draw = "<draw>";
	chart_draw = chart_draw+"<text size='16' x='235' y='35' width='100' height='20'>Year: "+yearToGraph+"</text>";
	chart_draw = chart_draw+"<text size='10' x='220' y='55' width='120' height='20'>Click to change year:</text>";
	
        //chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/rew.swf' x='230' y='75' width='15' height='15' />";
	chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/minus.swf' x='250' y='75' width='15' height='15' />";
	chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/plus.swf' x='270' y='75' width='15' height='15' />";
	//chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/ff.swf' x='290' y='75' width='15' height='15' />";
	
	if (!includeTherapy) {
	   chart_draw = chart_draw+"<text size='10' x='210' y='105' width='150' height='230'>In a group of 100 people\rwith similar characteristics,\r"+Math.round(datapoints[0][yearToGraphIndex]*100)+" will have died from cancer\rby year "+yearToGraph+", "+Math.round(datapoints[1][yearToGraphIndex]*100)+" will have died\rfrom causes other than\rcancer, and "+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex]*100))+" will still be\ralive."+"</text>";
	} else {
	   chart_draw = chart_draw+"<text size='10' x='210' y='105' width='150' height='230'>By year "+yearToGraph+", in a group of 100\rsimilar people:\r  "+Math.round(datapoints[4][yearToGraphIndex]*100)+" people will have died of\rnon-cancer causes,\r  "+Math.round(datapoints[3][yearToGraphIndex]*100)+" will have died of cancer,\r  "+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex]*100))+" will still be alive.\r\rWith therapy, "+(100-Math.round(datapoints[4][yearToGraphIndex]*100)-Math.round(datapoints[3][yearToGraphIndex]*100))+" will still\r be alive.</text>";}
	
	xpos = 5;
	ypos = 25;
	for (count=1;count<=100;count++) {
	  if (!includeTherapy) {
	      if (count<=Math.round(datapoints[1][yearToGraphIndex]*100)) {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/yellow.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }  else if (count<=Math.round(datapoints[0][yearToGraphIndex]*100)+Math.round(datapoints[1][yearToGraphIndex]*100)) {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/red.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }  else  {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/alive.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }
	  } else {
          if (count<=Math.round(datapoints[4][yearToGraph]*100)) {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/yellow.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }  else if (count<=Math.round(datapoints[4][yearToGraphIndex]*100)+Math.round(datapoints[3][yearToGraphIndex]*100)) {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/red.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }  else if (count<=Math.round(datapoints[0][yearToGraphIndex]*100) + Math.round(datapoints[1][yearToGraphIndex]*100)) {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/alive.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }else {
            chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/blank.swf' x='"+xpos+"' y='"+ypos+"' width='20' height='20' />";
          }
      }
      if (count%10==0) {
        ypos = ypos + 20;
        xpos = 5;
      } else {
        xpos = xpos + 20;
      }
	}
	chart_draw = chart_draw+"<image url='/cancer/i/full_screen.swf' x='305' y='5' width='20' height='15' />";
	chart_draw = chart_draw+"<text alpha='65' size='10' x='265' y='5' width='60' height='15' h_align='left' v_align='middle'>enlarge</text>";
	chart_draw = chart_draw+"</draw>";
	
	chart_links = "<link>";
	//chart_links = chart_links+"<area x='230' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph -5) + ")' />";
	chart_links = chart_links+"<area x='250' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph -1) + ")' />";
	chart_links = chart_links+"<area x='270' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph +1) + ")' />";
	//chart_links = chart_links+"<area x='290' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph +5) + ")' />";
	chart_links = chart_links+"<area x='305' y='5' width='20' height='15' target='toggle_fullscreen' />";
	chart_links = chart_links+"</link>";
	
	chart_filter = "<filter>";
	chart_filter = chart_filter+"<shadow id='low' distance='2' angle='45' alpha='50' blurX='5' blurY='5' />";
	chart_filter = chart_filter+"</filter>";
	
	chart_type = "<chart_type>pie</chart_type>";
	chart_data = "<chart_data>";
      chart_data = chart_data+"<row>";
      chart_data = chart_data+"<null/>";
      chart_data = chart_data+"<string>Non-cancer death</string>";
      chart_data = chart_data+"<string>Cancer death</string>";
      if (includeTherapy)  {
        chart_data = chart_data+"<string>Add'l alive w/ therapy</string>";  }
      chart_data = chart_data+"<string>Alive</string>";      
      chart_data = chart_data+"</row>";
      chart_data = chart_data+"</chart_data>";
		series_style = "<series_color><color>F0CB75</color><color>E87D7D</color><color>408040</color><color>FFFFFF</color></series_color>";
		chart_legend = "<legend layout='vertical' x='" + ((total_width*1) -140) + "' y='" + ((total_height*1) -65) + "' width='140' height='55' margin='5' fill_color='000000' fill_alpha='10' line_color='000000' line_alpha='0' line_thickness='0' bullet='square' size='11' color='000000' alpha='60' />";

	
    document.my_chart_1.Update_XML("<chart>"+"<license>LTAHVA4JESMO9UJ5CWK-2XOI1X0-7L</license>"+"<chart_rect hide='true' />"+chart_draw+chart_links+chart_filter+chart_type+chart_data+series_style+chart_legend+"</chart>", true, "reset");  
    }
    
    
function plotBarGraph(datapoints, graph_type, yearToGraph, includeTherapy, endYear) {

   numDataPoints = datapoints[1].length;
	plot_month_interval = endYear * 12 / (numDataPoints-1);
	yearToGraphIndex = yearToGraph * 12 / plot_month_interval; 


   chart_type = "<chart_type>stacked column</chart_type>";
  chart_data = "<chart_data>";
  chart_data = chart_data+"<row>";
  chart_data = chart_data+"<null/>";
  if (!includeTherapy)   {   
    chart_data = chart_data+"<string></string>";         
  } else {         
       chart_data = chart_data+"<string>no therapy</string>";
      chart_data = chart_data+"<string>w/ therapy</string>";
  }
  chart_data = chart_data+"</row>";
  if (!includeTherapy)   {   
    chart_data = chart_data+ "<row>" + "<string>Cancer\rdeath</string><number>"+Math.round(datapoints[0][yearToGraphIndex]*100)+"</number></row>";
    chart_data = chart_data+ "<row>" + "<string>Non-cancer\rdeath</string><number>"+Math.round(datapoints[1][yearToGraphIndex]*100)+"</number></row>";
    chart_data = chart_data+ "<row>" + "<string>Alive</string><number>"+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex]*100))+"</number></row>";
  } else {
    chart_data = chart_data+"<row>"+"<string>Cancer\rdeath</string><number>"+Math.round(datapoints[0][yearToGraphIndex]*100)+"</number><number>"+Math.round(datapoints[3][yearToGraphIndex]*100)+"</number></row>";
    chart_data = chart_data+"<row>"+"<string>Non-cancer\rdeath</string><number>"+Math.round(datapoints[1][yearToGraphIndex]*100)+"</number><number>"+Math.round(datapoints[4][yearToGraphIndex]*100)+"</number></row>";
    chart_data = chart_data+"<row>"+"<string>Alive</string><number>"+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex]*100))+"</number><number>"+(100-Math.round(datapoints[3][yearToGraphIndex]*100)-Math.round(datapoints[4][yearToGraphIndex]*100))+"</number></row>";      
  }
    chart_data = chart_data+"</chart_data>";
	
	chart_style = "<chart_rect x='30' y='10' width='" + ((total_width *1) -170) + "' height='" + ((total_height*1) -55) + "' />";	
	chart_style = chart_style+"<chart_border top_thickness='0' bottom_thickness='1' left_thickness='1' right_thickness='0' color='777777' />";
	chart_style = chart_style+"<chart_pref line_thickness='1.5' point_shape='circle' fill_shape='true' />";
	chart_style = chart_style+"<legend x='35' y='" + ((total_height*1) -40) + "' width='" + ((total_width *1) -70) + "' height='40' margin='5' fill_color='000000' fill_alpha='0' line_color='000000' line_alpha='0' line_thickness='0' bullet='square' size='11' color='000000' alpha='60' />";
	chart_style = chart_style+"<chart_label position='cursor' suffix='%' size='12' color='000000' alpha='50' />";
	chart_style = chart_style+"<chart_transition type='slide_up' delay='0.5' duration='0.5' order='series' />";
	chart_style = chart_style+"<axis_value min='0' max='100' suffix='%' size='10' color='000000' alpha='65' steps='5' />";
	
	series_style = "<series_color><color>E87D7D</color><color>F0CB75</color><color>99BF60</color></series_color>";
	
	chart_draw = "<draw>";
	chart_draw = chart_draw+"<text size='16' x='235' y='35' width='100' height='20'>Year: "+yearToGraph+"</text>";
	chart_draw = chart_draw+"<text size='10' x='220' y='55' width='120' height='20'>Click to change year:</text>";
	chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/minus.swf' x='250' y='75' width='15' height='15' />";
	chart_draw = chart_draw+"<image shadow='low' alpha='90' url='/cancer/i/plus.swf' x='270' y='75' width='15' height='15' />";
	if (!includeTherapy) { 
	  chart_draw = chart_draw+"<text size='10' x='210' y='105' width='150' height='230'>In a group of 100 people\rwith similar characteristics,\r"+Math.round(datapoints[0][yearToGraphIndex]*100)+" will have died from cancer\rby year "+yearToGraph+", "+Math.round(datapoints[1][yearToGraphIndex]*100)+" will have died\rfrom causes other than\rcancer, and "+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex]*100))+" will still be\ralive."+"</text>";
    } else{
	  chart_draw = chart_draw+"<text size='10' x='210' y='105' width='150' height='230'>By year "+yearToGraph+", in a group of 100\rsimilar people:\r  "+Math.round(datapoints[4][yearToGraphIndex]*100)+" people will have died of\rnon-cancer causes,\r  "+Math.round(datapoints[3][yearToGraphIndex]*100)+" will have died of cancer,\r  "+(100-Math.round(datapoints[0][yearToGraphIndex]*100)-Math.round(datapoints[1][yearToGraphIndex]*100))+" will still be alive.\r\rWith therapy, "+(100-Math.round(datapoints[4][yearToGraphIndex]*100)-Math.round(datapoints[3][yearToGraphIndex]*100))+" will still\r be alive.</text>";;
	  }
	chart_draw = chart_draw+"<image url='/cancer/i/full_screen.swf' x='305' y='5' width='20' height='15' />";
	chart_draw = chart_draw+"<text alpha='65' size='10' x='265' y='5' width='60' height='15' h_align='left' v_align='middle'>enlarge</text>";
	chart_draw = chart_draw+"</draw>";
	
	chart_links = "<link>";
	chart_links = chart_links+"<area x='250' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph -1) + ")' />";
	chart_links = chart_links+"<area x='270' y='75' width='15' height='15' url='javascript:plotGraph(null, null, " + (yearToGraph +1) + ")' />";
	chart_links = chart_links+"<area x='305' y='5' width='20' height='15' target='toggle_fullscreen' />";
	chart_links = chart_links+"</link>";
	
	chart_filter = "<filter>";
	chart_filter = chart_filter+"<shadow id='low' distance='2' angle='45' alpha='50' blurX='5' blurY='5' />";
	chart_filter = chart_filter+"</filter>";
	
	document.my_chart_1.Update_XML("<chart>"+"<license>LTAHVA4JESMO9UJ5CWK-2XOI1X0-7L</license>"+chart_type+chart_data+chart_style+series_style+chart_draw+chart_links+chart_filter+"</chart>", true, "reset");      		
}
	
	

	


   

