我是asp.net的初学者,想用图表向用户显示任何数据并且用户可以打印该图表,图表控制html代码:
<div id="MainContent_divl" class="div_l" style="float:left;direction:ltr;text-align:Left;">
<asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button3_Click" />
<input type="button" onclick="PrintDiv();" value="پرینت" />
<br />
<div align="center">
<asp:Label ID="Label1" runat="server" Text="Label" BackColor="Red" Font-Bold="True" ForeColor="White" Visible="False"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label" BackColor="Blue" Font-Bold="True" ForeColor="White" Visible="False"></asp:Label>
</div>
<br />
<asp:Chart ID="Chart1" runat="server" Height="579px" Width="4177px">
<Series>
<asp:Series Name="Series1"></asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"></asp:ChartArea>
</ChartAreas>
<BorderSkin BorderWidth="3" />
</asp:Chart>
</div>
这是一个打印按钮代码:
<input type="button" onclick="PrintDiv();" value="پرینت" />
这是为此目的的javasript代码:
<script type="text/javascript">
function PrintDiv() {
var divContents = document.getElementById("MainContent_divl").innerHTML;
var printWindow = window.open('', '', 'height=200,width=400');
printWindow.document.write('<html><head><title>DIV Contents</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
}
</script>
但是当想要打印时,图表在打印页面显示空白,会发生什么?我该如何解决?谢谢。