jones
jones

Reputation: 1453

PHPChart how to export to pdf,and image?

I'm using PHPChart for creating charts, now i want to have an option for exporting charts to pdf and images. Bellow is my code:

<link rel="stylesheet" type="text/css" href="/phpChart_Enterprise/js/src/jquery.jqplot.css" />
<!--<link rel="stylesheet" type="text/css" href="/phpChart_Enterprise/examples/examples.css" />-->
<!--[if lt IE 7]>
<script type="text/javascript" src="../../flot/excanvas.js"></script>
<![endif]-->
<!--[if lt IE 7]>
<script type="text/javascript" src="../../explorercanvas/excanvas.js"></script>
<![endif]-->
<!--[if lt IE 9]>
<script type="text/javascript" src="/phpChart_Enterprise/js/src/excanvas.js"></script>
<![endif]-->
<!--[if lt IE 7]>
<script type="text/javascript" src="../../flashcanvas/src/flashcanvas.js"></script>
<![endif]-->

<!-- BEGIN: load jquery -->
<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/jquery.js"></script>
<!-- BEGIN: load jqplot -->
<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/jquery.jqplot.js"></script>
<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/plugins/jqplot.categoryAxisRenderer.js"></script>
<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/plugins/jqplot.dateAxisRenderer.js"></script>
<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/plugins/jqplot.barRenderer.js"></script>
<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/plugins/jqplot.canvasAxisTickRenderer.js">   </script>
 <script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/plugins/jqplot.canvasTextRenderer.js"></script>
  <!--<script language="javascript" type="text/javascript" src="/phpChart_Enterprise/js/src/canvasHack2.js"></script>-->
<script type="text/javascript">
$(document).ready(function(){

    if (!$.jqplot.use_excanvas) {
        $('div.jqplot-target').each(function(){
            // Add a view image button
            var btn = $(document.createElement('button'));
            btn.text('View as PNG');
            btn.bind('click', {chart: $(this)}, function(evt) {
                evt.data.chart.jqplotViewImage();
            });
            $(this).after(btn);

            // add a save image button
            btn = $(document.createElement('button'));
            btn.text('Save as PNG');
            btn.bind('click', {chart: $(this)}, function(evt) {
                evt.data.chart.jqplotSaveImage();
            });
            $(this).after(btn);
            btn = null;
        });
    }

    $('#stackChart1').CanvasHack();
});
</script>

But when i click on generated buttons Save as PNG and View AS PNG browser goes to loading and down.

For any help and guid thanks.

Upvotes: 0

Views: 1787

Answers (1)

devXen
devXen

Reputation: 3132

Did you check out the image export example? It's all done in Javascript.

http://phpchart.com/phpChart/examples/export_image.php

Not sure about PDF export, but I believe it would require some server side script. See example below.

https://phpchart.uservoice.com/knowledgebase/articles/443666-how-to-export-my-chart-on-the-server-side-in-php

Upvotes: 2

Related Questions