Multiple Charts on One Page

Created on 25 July 2023, over 1 year ago
Updated 27 July 2023, over 1 year ago

Problem/Motivation

I have a website that allows users to submit change requests which are a single content type consisting of roughly 20 fields. I want to create an overview page that has separate charts for about six of these fields which would provide information like "number of change requests per category", or "number of successful/failed change requests", etc. Rather than having six different filtered charts on separate pages, I want them all on one page and subject to a single filter so that I can filter once and see all six charts update to reflect the filtered data.

I was able to successfully create a view with a page that displayed a single chart that more or less worked with the filter, but I could not figure out how to add more than one chart to the page no matter what I tried. At this point, I spent two days trying to figure it out on my own and figured it is a good time to ask for some help or advice.

Attempted Solutions

1. I tried going through these Charts docs β†’ , however the documentation is very limited. There were lots of how-to links, but none of them addressed my query.

2. I found this closed issue β†’ from one year ago, but I did not understand the answer which referred to using a regular views attachment, which I could not find when building the view. The answer was only two sentences and not enough to go off of to resolve my issue. This is a shame because this issue most closely resembles what I am trying to achieve.

3. I found another issue β†’ , this time 10 years old, and the answer was simply that the charts module should be able to handle any number of charts on one page, but with no explanation how to achieve this.

4. I tried to create chart blocks instead but it was resulting in php errors, probably because I was winging it at that point and making obvious mistakes.

5. I tried to create a grid view, but I couldn't find how to insert the charts in the grids.

More Info

  • I would like to achieve this with views integration if possible and without having to manually write code. I can settle on a code answer if there is no better way, but ideally I want to learn how to achieve this with the tools built into core and the Charts module.
πŸ’¬ Support request
Status

Fixed

Version

5.0

Component

Views integration

Created by

πŸ‡¨πŸ‡¦Canada ciesinsg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ciesinsg
  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Hi @ciesinsg, sorry to hear you've put in significant effort with no luck. The good news is that there are several ways to put multiple charts on the same page, and none of them require a code solution.

    The approach you mention in #2 could be a good solution for you. To add an attachment, you should look at the toolbar under the heading "Displays" where you will see "Page". There is a "+ Add" to add a new display to your view. Select "Attachment" (you will also see "Chart attachment", but that us for a different use-case, so please ignore). Then you just configure the attachment the same way as your page display, except you will need to "attach" the attachment to your page display and make sure it inherits your view's exposed filters.

    The other approach you could try would be to make all your views as block displays (rather than pages), and then use Layout Builder to create your grid and then just place the blocks in the grid. The tricky part there has to do with hiding the filters your don't need so you just have one filter showing. There are ways, they just take a while to explain.

    I'll try to do a tutorial soon. Please also feel free to request tutorial videos here: https://www.drupal.org/project/charts/issues/3317614 β†’ (I've been disappointed by no one commenting on this ticket!)

  • πŸ‡¨πŸ‡¦Canada ciesinsg

    Hi @andileco, thanks for the tips! I did try using the attachments yesterday but unfortunately I was unsuccessful. What happens is that the attachment chart changes the initial chart I create. Thankfully I discovered the solution, so I will outline it below in case it helps someone in the future:

    Recreate Issue

    In this example, I have one content type "change request" and I was creating two charts from the fields: category and reason.

    1) + Add View - name the view, show content of type change request, checked the "create a page" option, and display a chart of fields.

    2) Set up my first chart on this page. I added the category field for the labels, and a second counted category field to count the number of posts per category.

    3) Modified the settings on the chart (Format -> Chart settings) to use the label and data field and successfully outputted a "category chart".

    4) Clicked "+ Add" and selected attachment. In the Attachment settings, I attached it to Page (initial chart), changed position to after, and enabled "Inherit exposed filters". The rest of the settings on the attachment seemed to be cloned from the original page, including the fields I added and the chart settings.

    5) Added the reason field for the labels, and a second counted reason field to count the number of posts per reason. During this process, I selected the option "For This attachment (override)" so that the fields successfully added only for the attachment.

    6) Once again I went into the chart settings (Format -> Chart settings) and changed the chart information. I changed the title, labels, and data, however there was nowhere that I could select that previous option "For This attachment (override)". The result was that both charts changed and showed the labels and data for "reason".

    Solution

    So it seems that the "Format -> Chart | settings" option doesn't have the "For This attachment (override)" option, at least not in Drupal 10. Instead, you have to click Format: Chart | Settings (click chart) on the attachment, and there you can select the attachment as override. Once you do this, the settings are changed only for the attachment and the previous chart remains unchanged.

    I wanted to include this explanation because this option is easy to miss and I completely missed it yesterday.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024