php - Symfony2 only use values from json_encode -
i'm getting information database , holding information in array. i've used {{dump(weights)}}
in twig
template, see below dump of array:
if use weights|json_encode()
can information:
which okay, graph needs data in format - [69,72]
.
for example, how code should graph:
var geckoweight = { labels: dates, datasets: [ { label: "front", fillcolor: "rgba(0, 0, 0, 0.15)", strokecolor: gradient, pointcolor: gradient, pointstrokecolor: "#202b33", pointhighlightstroke: "rgba(225,225,225,0.9)", data: [69,72] } ] };
what best way manipulate data suit needed in graph data?
i (in model method or controller):
class mycontroller extends controller { public function someaction() { $data = array( array('weight' => 69), array('weight' => 72), ); $graphdata = array_map(function($i) { return $i['weight']; }, $data); return $this->render('default/index.html.twig', array( 'data' => $weights, )); }
on twig template:
<script> var weights = {{ data|json_encode }}; </script>
Comments
Post a Comment