1

My users have a field collection with 2 fields: 'Points' (integer) and 'Date' (date). I'd like to create a line graph of the 'Points' with the Charts module and use 'Date' as labels. I thought this would be easily achievable with Views, but for some reason, the chart isn't displaying in my view. This is an export:

$view = new view();
$view->name = 'linegraph';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'linegraph';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'chart';
$handler->display->display_options['style_options']['type'] = 'line';
$handler->display->display_options['style_options']['library'] = '';
$handler->display->display_options['style_options']['label_field'] = 'field_date';
$handler->display->display_options['style_options']['data_fields'] = array(
  'field_points' => 'field_points',
  'field_date' => 0,
);
$handler->display->display_options['style_options']['field_colors'] = array(
  'field_date' => '#2f7ed8',
  'field_points' => '#0d233a',
);
$handler->display->display_options['style_options']['width'] = '';
$handler->display->display_options['style_options']['height'] = '';
$handler->display->display_options['style_options']['xaxis_labels_rotation'] = '0';
$handler->display->display_options['style_options']['yaxis_labels_rotation'] = '0';
/* Relationship: User: Points (field_points) */
$handler->display->display_options['relationships']['field_points_value']['id'] = 'field_points_value';
$handler->display->display_options['relationships']['field_points_value']['table'] = 'field_data_field_points';
$handler->display->display_options['relationships']['field_points_value']['field'] = 'field_points_value';
$handler->display->display_options['relationships']['field_points_value']['required'] = TRUE;
$handler->display->display_options['relationships']['field_points_value']['delta'] = '-1';
/* Field: Field collection item: Date */
$handler->display->display_options['fields']['field_date']['id'] = 'field_date';
$handler->display->display_options['fields']['field_date']['table'] = 'field_data_field_date';
$handler->display->display_options['fields']['field_date']['field'] = 'field_date';
$handler->display->display_options['fields']['field_date']['relationship'] = 'field_poins_value';
$handler->display->display_options['fields']['field_date']['label'] = '';
$handler->display->display_options['fields']['field_date']['element_label_colon'] = FALSE;
/* Field: Field collection item: Points */
$handler->display->display_options['fields']['field_points']['id'] = 'field_points';
$handler->display->display_options['fields']['field_points']['table'] = 'field_data_field_points';
$handler->display->display_options['fields']['field_points']['field'] = 'field_points';
$handler->display->display_options['fields']['field_points']['relationship'] = 'field_points_value';
$handler->display->display_options['fields']['field_points']['label'] = '';
$handler->display->display_options['fields']['field_points']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_points']['settings'] = array(
  'thousand_separator' => ' ',
  'prefix_suffix' => 1,
);
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

What's going wrong and how can I solve this?


This question is part of How to create a line graph of the total user points on a profile page?.

  • I have just created a view using charts module and it is working fine. I am also using field collection fields. Can you provide your view in an image? – Ahmad Nov 13 '14 at 7:28
  • Well, my view is simply empty, so there is nothing to be seen. Is my exported view working for you? Can you eventually export yours in an answer? – Jeroen Nov 13 '14 at 10:07
  • Hey @Jeroen: an "old" question, but first things first ... Can you create a tabular view (using "table" as views format) of the data you ALSO want to show as a chart? Reason why I ask: if you can't create such tabular view (first), then the input for the charts module can impossibly be correct, and that incorrect input will for sure not result in a correct chart, understand? – Pierre.Vriens Jul 28 '16 at 18:36
1

Here is my exported view. It is working fine. Hope that it may help you.

$view = new view();
$view->name = 'test_view';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test view';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'test view';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '3';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['quantity'] = '9';
$handler->display->display_options['style_plugin'] = 'chart';
$handler->display->display_options['style_options']['yaxis_title'] = 'Weight';
$handler->display->display_options['style_options']['yaxis_min'] = '0';
$handler->display->display_options['style_options']['label_field'] = 'field_collection_date';
$handler->display->display_options['style_options']['data_fields'] = array(
  'field_collection_weight' => 'field_collection_weight',
  'field_collection_date' => 0,
);
$handler->display->display_options['style_options']['field_colors'] = array(
  'field_collection_date' => '#2f7ed8',
  'field_collection_weight' => '#0d233a',
);
/* Relationship: Content: Actual mesaurment (field_actual_mesaurment) */
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['id'] = 'field_actual_mesaurment_value';
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['table'] = 'field_data_field_actual_mesaurment';
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['field'] = 'field_actual_mesaurment_value';
$handler->display->display_options['relationships']['field_actual_mesaurment_value']['delta'] = '-1';
/* Field: Field collection item: Date */
$handler->display->display_options['fields']['field_collection_date']['id'] = 'field_collection_date';
$handler->display->display_options['fields']['field_collection_date']['table'] = 'field_data_field_collection_date';
$handler->display->display_options['fields']['field_collection_date']['field'] = 'field_collection_date';
$handler->display->display_options['fields']['field_collection_date']['relationship'] = 'field_actual_mesaurment_value';
$handler->display->display_options['fields']['field_collection_date']['alter']['strip_tags'] = TRUE;
$handler->display->display_options['fields']['field_collection_date']['settings'] = array(
  'format_type' => 'day_month_year',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
);
/* Field: Field collection item: Your weight */
$handler->display->display_options['fields']['field_collection_weight']['id'] = 'field_collection_weight';
$handler->display->display_options['fields']['field_collection_weight']['table'] = 'field_data_field_collection_weight';
$handler->display->display_options['fields']['field_collection_weight']['field'] = 'field_collection_weight';
$handler->display->display_options['fields']['field_collection_weight']['relationship'] = 'field_actual_mesaurment_value';
$handler->display->display_options['fields']['field_collection_weight']['settings'] = array(
  'thousand_separator' => ' ',
  'decimal_separator' => '.',
  'scale' => '2',
  'prefix_suffix' => 1,
);
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Author uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'node';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'goal' => 'goal',
);
/* Filter criterion: Date: Date (field_collection_item) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'field_collection_item';
$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['relationship'] = 'field_actual_mesaurment_value';
$handler->display->display_options['filters']['date_filter']['operator'] = 'between';
$handler->display->display_options['filters']['date_filter']['exposed'] = TRUE;
$handler->display->display_options['filters']['date_filter']['expose']['operator_id'] = 'date_filter_op';
$handler->display->display_options['filters']['date_filter']['expose']['label'] = 'Period';
$handler->display->display_options['filters']['date_filter']['expose']['operator'] = 'date_filter_op';
$handler->display->display_options['filters']['date_filter']['expose']['identifier'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['expose']['remember_roles'] = array(
  2 => '2',
  1 => 0,
  3 => 0,
  4 => 0,
);
$handler->display->display_options['filters']['date_filter']['form_type'] = 'date_popup';
$handler->display->display_options['filters']['date_filter']['date_fields'] = array(
  'field_data_field_collection_date.field_collection_date_value' => 'field_data_field_collection_date.field_collection_date_value',
);
$handler->display->display_options['filters']['date_filter']['date_method'] = 'AND';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-view';
| improve this answer | |
  • Thank you for the export. Would you like to explain which fields you used? I can see that you have field collections called 'Weight' and 'Date', but how do they correspond? Which fields do they contains? Etc. – Jeroen Nov 13 '14 at 22:03
  • field_actual_mesaurment is a field collection used in the content type. field_collection_weight and field_collection_date are the field collection fields. – Ahmad Nov 14 '14 at 7:25
  • Okay, so your field collection is part of a content type. Is the chart also displayed correctly if the field collection is assigned to users? Maybe that's the problem. – Jeroen Nov 14 '14 at 12:59

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.