2

I have 4 nodes with a field status (just an example, it could have more fields). The content type is set to create revisions on every update.

What I need is to create a chart in views like the one below, using Charts and Highcharts.

enter image description here

So, first time I create the 4 nodes:

  • 3 have status = No Run;
  • 1 have status = Blocked;

After updating the 4 nodes, a new revision is created and now each node has a different status value:

  • 1 have status = No Run;
  • 1 have status = Blocked;
  • 1 have status = Passed;
  • 1 have status = Not Completed;

On the third revision:

  • 2 have status = Passed;
  • 2 have status = Not Completed;

... and so on...

I tried everything in views without success. I started by trying to show the data needed in table format but I can only view the latest revision, not all.

Anyone has a clue on how to accomplish this?

I'm willing to make this with code also but I would like to try views first.

Thanks!

  • Which charting-related module is this question about? Consider adding that to your (interesting) question also. – Pierre.Vriens Nov 23 '15 at 8:56
2

Ok,

After some struggle, I managed to get the results I needed so, I will share how to do it. Hope it helps anyone with the same question.

At the time of this answer, this will only work with the most recent Dev version. Also, after that, you have to apply this patch. It won't work unless you make these two steps.

On your content type, check if you have the Create new revision option checked.

In views, create a new view to show Content revisions and format as Chart. Change the following inside views:

===== First Display =====

Remove the Content revision: Content relationship.

Remove the Content: Published (Yes) filter.

If you have more than one content type, the way you filter (at least I did it this way) is to add a field to the Filter criteria like this: Content (historical data): [your field] (not empty).

Set Use aggregation to yes.

Add a Content revision: Nid field to the display and set aggregation to COUNT.

On the Chart settings, select field Content revision: Updated date to provide labels and COUNT(Content revision: Nid) to provide data.

The result is a display that shows the total of nodes for each revision (x-axis date).

===== Second (and similar) displays =====

Now, you create chart add-on displays for each of the different states/values of your data field (in my case it was a status_field).

The settings for these displays are the same as the first one with one difference:

Add the [your field] field to the filter section and filter by one of the states/values. You will have to do this for each dispay, each one represents the chart for each state.

Combine the chart add-on with parent chart.

Finally, to get the chart as stacked, you have to create some code. Add the following code to your module:

function mymoudle_chart_alter(&$chart, $chart_id) {
    if ($chart_id == '[my_chart_machine_name]__[first_display_machine_name]') {
    $chart['#stacking'] = TRUE;
}

Notes: remove the [ and ] from above example but keep both undersores (__).

And that's it. This is the result I got:

enter image description here

I have the update date of the revision to show as unix timestamp but you can have it as you like!

As suggested, here is a similar chart but using 'bar' type:

enter image description here

  • Thanks for clarifying the question (I wanted to be sure you asked about the Charts module). In your answer here you refer to the patch in comment nr 12 in that issue. But I'm about sure it does not apply anymore to the "most recent dev" version. It had to be rerolled, which is what is now what the path in nr 31 is about. Can you double check which patch (as in nr 12 or 31) you used (and update your answer if needed)? – Pierre.Vriens Nov 23 '15 at 11:04
  • Looks like you used a chart type = "Area chart", which resulted in an interesting chart (as in the image you added). Would be interesting to see how the chart would look like if you would use chart types = "column" or "bar" (for each of the chart add-ons). Maybe you want to add to add a similar screenprint for those types of charts? Maybe also indicate which charting library you used (Google charts of Highcharts)? – Pierre.Vriens Nov 23 '15 at 11:17
  • Nice! +1 ... Also for your own answer. PS: I'm considering adding "stacked (y/n)" as an extra option in the Views UI (for relevant chart types), as well as some type of 'raw_options' to be passed to the charting engine. – Pierre.Vriens Nov 23 '15 at 19:56
  • Hi Pierre, adding that option would be great. I also suggest that it would be possible to change the "Provide Labels" field on chart add-on settings. If you have multiple chart add-ons (I have 9 for my project) and you need to change the field used for labels on the parent, the add-ons have to be deleted and recreated from scratch. – zephirus Nov 23 '15 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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