1

How to render a Column Chart using data from Views PHP custom field (BAR Number (PHP custom) in the screenshot below)?

enter image description here

I am trying to achieve a Column Chart; with each bar in the chart being distinct count number of "bar number".

  1. I have tried using aggregation (with charts module chart add-on enabled), but does not give option to aggregate/count on PHP custom fields.
  2. have tried Google Chart Tools module, but again it does not consider PHP Views custom fields for Grouping.

Just for more information on what I am trying to achieve, please refer below Requirement screenshot!

Thanks in advance!

enter image description here

0

1 Answer 1

0

A work around for issue 1. & 2. Add Bar number as a field to each study node. Then add field to view, and aggregate.

How exactly is the Bar Number being calculated? You could use Rules to calculate this value when node is saved and save the calc number to your Bar number field. If there is no calculation, then ignore this part.

Use field permissions to not allow certain roles to change the value of this field, if needed.


Add a new field called Bar Number (machine name: field_bar_number) to your study content type.

You can create a custom module.

mymodule.info

name = My Module
description = Makes calculation for Bar Number field in Study content type.
package = Custom
version = 7.x-1.0
core = 7.x

mymodule.module

/**
 * Implements of hook_node_presave
 */
function MYMODULE_node_presave($node) {
  if ($node->type =='study') {
    // calculates bar number
    $node->field_bar_number = $node->some_field - $node->other_field;                          
  }
}

Use Views Bulk Operations and set title = title, and save again all your 500 nodes. As your custom module makes the calculation and sets the bar number before the node is saved. VBO Tutorial.

3
  • Thanks for the help. Bar number is calculated in the view, in PHP custom date_diff => "Collection_date - Date_of_Onset" and some calculations to calculate bar number. And, There are around 500 study node records.
    – shablm
    Oct 26, 2017 at 6:45
  • @Maddy see my updated answer.
    – No Sssweat
    Oct 26, 2017 at 7:08
  • Many thanks for the help, shall try out this and will get back to you with the results. cheers
    – shablm
    Oct 27, 2017 at 0:13

Your Answer

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

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