I have a table view with both filters and exposed filters, and attached to it there is another view that uses views_aggregator_plus to display a summary of months and different value counts.

I want to have the attachment visualized so I attached ChartJs script to the page view and had another function loop through the attachment html table rows to fetch the data while separating each column into its own array.

This works though I am not sure. It doesn't feel right. Wouldn't it be better if I pushed the values from the view directly to the script rather than have it done by the browser?

I am not sure about how to do it, but I found the values needed in hook_view_post_render under $view->style_plugin->rendered_fields..

How to proceed from there? Or maybe there is an entirely different and better way to achieve the same?


1 Answer 1


It really depends on what you want and what data structure you have.
Normally I would say if you want only chart on the page/views, than create a new views type (Like block, page, etc) and then you can do whatever you want, and you can still attach it to another views. (I think this is it: https://www.drupal.org/docs/8/creating-custom-modules/building-a-views-display-style-plugin-for-drupal-8)
If you just want to show a chart side-by-side with some other data, maybe you need to create a new field (for views), than you can put there the stuff. (https://www.webomelette.com/creating-custom-views-field-drupal-8)
You can also hook in any time to a view, but it will make a mess after a while, however, every time you need to use the drupalSettings (Pass variable to drupalSettings) if you want to pass php data to javascript and some custom JS code to glue the ChartJS to the drupalSettings.

  • What I want is mentioned in the first few sentences. I apologize if it wasn't clear enough. I did it in views_post_render like this: ` foreach ($view->result as $id => $row) { do stuff } $output['#attached']['drupalSettings']['module']['charttjs']['stuff']= done stuff`
    – Jed_BH
    Jun 1, 2019 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.