0

I have a symfony3 project with working Highcharts functions implemented through the ob/highcharts-bundle and I really like the way the generated charts look with a custom theme.

I would like to be able to run a script on the server that generates an email and along the way builds the charts that I need (complete with my custom theme) and saves to the server so I can link to them from the email.

I've previously done this in pChart, and saving an image on the server from a script is as easy as $myPicture->autoOutput('myimage.png'). While that's easy, I prefer the look of charts from Highcharts.

Is there a similar simple way to do this something like this using Highcharts?

My scripts look like this:

// Controller

$xdata  = array(1, 2, 3, 4);
$data_series = array(
    0 => array(
        "name" => "Series 1",
        "data" => array(
            0 => 2.0, 1 => 0.0, 2 => 5.0, 3 => 2.3, 4 => 0.45, 5 => 0.4
         )
     )
);

$ob = new Highchart();
$ob->chart->renderTo('trendchart'); // id of the div where the chart gets rendered
$ob->title->text('Chart title');
$ob->xAxis->categories($xdata);
$ob->series($data_series);

return $this->render('dashboard/main.html.twig', [
    'trendChart' => $ob,
]);

and I render this in a twig template:

// twig template

{% extends 'base.html.twig' %}

{% block javascripts %}
    {{ parent() }}

    <script src="//code.highcharts.com/highcharts.js"></script>
    <script src="//code.highcharts.com/modules/exporting.js"></script>
    <script src="{{ asset('js/highchartThemes/mytheme.js') }}"></script>

    <script>
        {{ chart(trendChart) }}
    </script>
{% endblock %}

{% block body %}
    <div id="trendchart"></div>
{% endblock %}

What I'm hoping for is to make a call from my controller like:

$ob->save('myimage.png');

Does anyone know of a simple/clean way to do something like this?

ehymel
  • 1,360
  • 2
  • 15
  • 24
  • You can setup your own server for rendering chart images - see docs http://www.highcharts.com/docs/export-module/setting-up-the-server or by posting request to Highcharts website - see answers http://stackoverflow.com/questions/8802528/how-to-save-an-image-of-the-chart-on-the-server-with-highcharts http://stackoverflow.com/questions/11530634/highcharts-export-to-base64/11541810#11541810 – morganfree Apr 10 '17 at 09:55
  • Thanks for the comment @morganfree. I know I can set up a server for this, but I was hoping for a MUCH simpler solution. pChart does this with such ease that I was looking for something equally simple. – ehymel Apr 10 '17 at 14:51

0 Answers0