How do I plot content created per month on a column chart?

Created on 20 February 2024, 4 months ago
Updated 26 February 2024, 4 months ago

Problem/Motivation

I am trying to create a column chart that plots the amount of Change Requests (custom content type) created per month, and how many of those Change Requests are successful. The success is indicated by a list field which is set to the option "Fully Successful". So in short, for each month on the chart, there would be two columns. One showing the number of change requests created, and the second showing how many of those change requests are successful. I attached a picture of an example of the chart.

Points of Confusion

1) How do I count each change requested created per month? (Read attempts section for clarification)

2) How do I repeat this process for the success column whereby I count how many change requests exist with a list field equal to "Fully Successful" per month?

Attempts

I have spent lots of time reading the Charts documentation, watching the video, and reading blog posts but I haven't had any success yet in my attempts to plot these charts. The docs are great and have some unique examples, but these examples didn't help me better understand how to achieve what I am specifically trying to achieve. Additionally, I did a quick search for existing issues but wasn't able to find anything.

1) As a clarification for point 1, I attempted to create this by adding a new field for "Authored on" and setting the aggregation to count but this creates a new data point for each unique date & time the change requests are submitted on, and gives each a count of 1. Instead, I just want the chart to display 12 data points, one for each month, and to count how many requests exist for each month.

I don't have more attempts to list here because my inability to chart the data per month prevented me from attempting to repeat the process for the second column.

Conclusion

In conclusion, I was hoping someone could advise me on how I can achieve what I am going for. Any kind of help would be very useful as I have been stuck on this for weeks with very little progress.

πŸ’¬ Support request
Status

Closed: works as designed

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, this really just an issue with views - it's not great at aggregating on this field. Try it with a table display, and you will have the same issue. Here's a question that's similar to yours: https://drupal.stackexchange.com/questions/181900/aggregating-by-date-field

    I think there are a bunch of relatively easy code-based fixes...are you comfortable working in PHP?

  • πŸ‡¨πŸ‡¦Canada ciesinsg

    Hi @andileco, I am okay with PHP, but I found a solution that worked in views alone, although I had to compromise and enable stacking on my column chart. I'll include the solution below in case other users find it useful.

    Solution

    As with other Charts, it's best to start off with a table as this can later be changed to a Chart once you're happy with how the table looks.

    1. Enable Aggregation as this will be needed for next steps
    2. Add the "Authored on" field and set the aggregation to group results. I named this one "Month" as it will show the month name once all the steps are followed.
    3. Add the "Authored on" field once again, but this time set the aggregation to count distinct. I named this one "Submitted" as it results in how many change requests exist that month.
    4. Add additional data columns. In my case, I added the "Success" field which is a list with "Fully successful", "Partially successful" and "Unsuccessful" where only one option can be selected. Set the aggregation to group results.
    5. Add a new Sort Criteria. I added "Authored on" here and set the granularity to "Month" which is what ends up sorting the previously defined fields into months and allows the chart to chart the data monthly.
    6. Change the format to chart. In my case, I set this to be a column chart as it shows monthly data in an easy to read way.
    7. Change the chart settings. I set the label to be "Month". I also enabled stacking which is what resulted in the chart showing actually useful data. Finally I added submitted and success as data fields.

    Stacking

    This is for anyone not familiar with stacking. Essentially, as the name implies, this stacks data points with multiple possibilities into a single column. In my case, each change request can be set to either fully successful, partially successful, or unsuccessful, but the total number of change requests stays the same. This results in a column on the chart that stackks different colors representing how many fall into the different success categories. All together, they add up to the total number of change requests, so one column is able to show both the total number submitted per month, and how many fall into each different category. It is not as easy to read as separate columns representing each success, however it takes up far less space and actually looks much nicer in my opinion. The main benefit of this is that instead of having 3 columns for each month, which would result in 36 columns, it can show the same data in only 12 columns.

  • Status changed to Closed: works as designed 4 months ago
Production build 0.69.0 2024