How to print a google chart using itextsharp in asp.net?

591 Views Asked by At

What I am trying to do is to set the chart image value to a hiddenfield. I have a working google chart which is generated on code behind and assigned to div_chart.

Here's my asp code:

     <script type="text/javascript" src="https://www.google.com/jsapi"></script>
           <center>
                <asp:ImageButton ID="ImageButton1" runat="server" ImageAlign="AbsMiddle" ImageUrl="~/images/acroread.png" OnClick="btnPDF_Click1" OnClientClick="return ExportToPDF(this)" ToolTip="Download PDF"/>
                    <asp:Button ID="btnPDF" runat="server" OnClientClick="return ExportToPDF(this)" ToolTip="Download PDF" OnClick="btnPDF_Click1" />``

                </center>

        <input id="chart_data" />
                <asp:Literal ID="ltChart" runat="server"></asp:Literal>
                <div id="div_chart" style="height: 400px; text-align: left;"></div>

</form>

Then i have some js code underneath the tag, where I am trying to set the image value to the hiddenfield:

<script type="text/javascript" src="http://cdn.rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.min.js"></script>
<script type="text/javascript">
    function ExportToPDF(btnExport) {
        ExportToImage(btnExport);
        return false;
    }
    function ExportToExcel(btnExport) {
        ExportToImage(btnExport);
        return false;
    }
    function ExportToImage(btnExport) {
        html2canvas($("#div_chart")[0]).then(function (canvas) {
            var base64 = canvas.toDataURL();
            $("[id*=chart_data]").val(base64);
            __doPostBack(btnExport.name, "");
        });
    }
</script>    

but when i try to access to my hiddenfield value on codebehind i get null values.

string base64 = Request.Form["chart_data"]

any ideas on how can i get the hiddenfield value? or if I am assigning it the wrong way: how to set it to it right?

0

There are 0 best solutions below