I am creating graphs using arcpy and facing this error while I give the input layer from the mxd.

In case, if I give the input from direct shapefile, then graphs are generated. Kindness is required in this issue. The code I have written is given by:
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">,</SPAN> sys
relpath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>dirname<SPAN class="punctuation token">(</SPAN>sys<SPAN class="punctuation token">.</SPAN>argv<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>relpath <SPAN class="operator token">+</SPAN> r<SPAN class="string token">"\map.mxd"</SPAN><SPAN class="punctuation token">)</SPAN>
index_layer1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Index_Layer"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
input_data <SPAN class="operator token">=</SPAN> <SPAN class="string token">"E:\Python\Utility\map data\Index_Layer.shp"</SPAN>
required_graphs <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'NCI_2011_'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'N_SI_2011_'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'N_IDDI_201'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'N_IDDI_202'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'N_CI_2014_'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'N_SI_2014_'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'N_IDDI_203'</SPAN><SPAN class="punctuation token">]</SPAN>
input_template <SPAN class="operator token">=</SPAN> <SPAN class="string token">"E:\Python\Utility\graphs\sample.grf"</SPAN>
<SPAN class="comment token">#Getting required graphs</SPAN>
<SPAN class="keyword token">for</SPAN> x <SPAN class="keyword token">in</SPAN> required_graphs<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Creating graph of "</SPAN> <SPAN class="operator token">+</SPAN> x
<SPAN class="comment token"># Create the graph</SPAN>
graph <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Graph<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Add a horizontal bar series to the graph</SPAN>
graph<SPAN class="punctuation token">.</SPAN>addSeriesBarHorizontal<SPAN class="punctuation token">(</SPAN>index_layer1<SPAN class="punctuation token">,</SPAN> x<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Specify the title of the left axis</SPAN>
out_graph_bmp <SPAN class="operator token">=</SPAN> <SPAN class="string token">"E:/Python\Utility/graphs/_{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN><SPAN class="string token">".jpg"</SPAN>
graph<SPAN class="punctuation token">.</SPAN>graphAxis<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="comment token"># Specify the title of the bottom axis</SPAN>
graph<SPAN class="punctuation token">.</SPAN>graphAxis<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">=</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="comment token"># Specify the title of the Graph</SPAN>
graph<SPAN class="punctuation token">.</SPAN>graphPropsGeneral<SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">=</SPAN> x
<SPAN class="comment token"># Output a graph, which is created in-memory</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>MakeGraph_management<SPAN class="punctuation token">(</SPAN>input_template<SPAN class="punctuation token">,</SPAN> graph<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"graph_{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Save the graph as an image</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SaveGraph_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"graph_{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>x<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> out_graph_bmp<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"IGNORE_ASPECT_RATIO"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">592</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1388</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>