score:8
Accepted answer
quick & "dirty" answer : set the variable in your twig file using balises, and use those vars in your js file.
<script>
var foo = {{ bar }};
</script>
score:14
you can generate javascript as twig template:
monthscontroller.php
public function scriptaction()
{
// some logic
return $this->render('acmedemobundle:months:script.js.twig', array(
'user_months' => $user_months
));
}
routing.yml
javascript_route:
path: /generated-scripts/month.{_format}
defaults: { _controller: acmedemobundle:article:script, _format: js }
requirements:
_format: js|json
script.js.twig
$(function () {
var options = {
chart: {
type: 'bar'
},
title: {
text: 'budget for months'
},
xaxis: {
categories: ['spent', 'saved']
},
yaxis: {
title: {
text: 'fruit eaten'
}
},
series: []
};
{% for user in user_months %}
options.series.push({ name: '{{ user.name }}', data: [{{ user.months|join(',') }}] };);
{% endfor %}
$('#container').highcharts(options);
});
Source: stackoverflow.com
Related Query
- Send variables from Symfony2 PHP file to js file
- HIGHCHARTS - Jquery/Ajax access php variables from the php file called by ajax
- How to send json to highcharts from php
- load data from text file into HIGHCHART graphic using PHP
- How do I pass a PHP variable from one file to another multiple times?
- Highcharts Won't load from php json, but it could load from data.json file
- Send JSON data to highcharts pie from asp.net MVC controller in C#
- Pass function to jquery from php
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- How to populate a Highcharts axis with string formatted data from a PHP array
- JavaScript code inside TypeScript file .ts not working
- Passing a JavaScript function from JSON encoded PHP
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- How to add php data into highchart js file in php
- PHP - getting real time data from the database
- Highcharts multiple series json from php
- Generate image in a folder from Highchart in PHP
- Pass a textfield value from php to javascript
- passing json values to highcharts from .net code behind
- Highcharts series setData from ajax php procedure
- Generating Highcharts from MySQL data with PHP does not work
- Remove Square Bracket From Array Key PHP
- How can i export row data from highchart to excel file and not csv?
- Simple, Open source PHP wrapper for Highcharts library
- Use value from prompt as highcharts export file name
- Creating a Highchart with multiple series from a JSON file
- Remove gap in Highcharts column chart from null value from JSON file in React
- Highcharts dynamicly update chart from csv file
- Generating json data for StockChart from PHP
- Highcharts not displaying data but drawing chart when reading from CSV file
More Query from same tag
- How to download Highchart PDFs in Mobile Apps?
- Highstocks - Place a line between columns when using datetime axis
- Highcharts, trying to regulate maximum height of chart columns NOT including Axes
- Highcharts img in html title; onerror doesn't fire even with Highcharts Security AST set
- Create a floating bar in HighCharts cloud
- How to exchange data between a form, a php file and a javascript file
- highstock 1.3 / highcharts 3.0 beta navigator lagging
- Highcharts: when exporting, unselected series should not show in the legend
- Update chart border color with plotband color in angular gauge
- highcharts and different yAxis for different categories
- Make the chart display current year in HighChart
- highcharts, bar chart legend with verticalAlign top not working
- How to hide series name from tooltip in Highcharts scatter plots for linear regression
- how to use Kendo chart library in Server side
- Different X values for different columns on highchart
- How to change zone line color in highcharts
- Multiple highstock charts on one page
- highchart - display value in xaxis as the value I get from the chart data as is without conversion
- Highcharts: How to remove the color under the data line in the Navigator
- npm throws this error '"**/node_modules/@angular/core/core"' has no exported member 'ɵɵFactoryDef'
- Set custom legend item symbol (or icon) in HIghcharts
- Angular : Filter object data to build a Highchart Widget with distinct elements attributes
- Ajax highcharts PieChart not displaying data
- Highstock bottom chart not shown
- Multiple Highcharts on a PDF page - SVG Page Layout
- Highcharts: Parse multi-variable JSON data
- Highcharts: Set DPi and resolution for scientific papers
- how to use function (chart) in react?
- Where to set displayed data vs plotted data in Highcharts?
- Trying to provide a list of symbols (per series) for Highcharts line graph in iReport