Hey

I tested the charts views module with highcharts.
See attached image.

As data value in the chart the ID is used and not the field value.
see screenshot, table at the bottom.

Comments

quicksketch’s picture

As data value in the chart the ID is used and not the field value.

In the View configuration, do you have the field selected with a checkbox in the "Data" column? If you could post a screenshot of the configuration of your display format with the chart configuration open, that would help me reproduce this problem. As is, it looks like you might just have the view misconfigured.

quicksketch’s picture

Another way of saying this: what's displayed in the table is not necessarily what's used by the chart. In the chart configuration, you must select which fields will be used as chart data explicitly.

skyredwang’s picture

Priority: Normal » Critical

I can confirm this bug. Below is my exported Views

$view = new view();
$view->name = 'chart';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'chart';
$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'] = 'chart';
$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'] = 'none';
$handler->display->display_options['style_plugin'] = 'chart';
$handler->display->display_options['style_options']['type'] = 'column';
$handler->display->display_options['style_options']['library'] = '';
$handler->display->display_options['style_options']['label_field'] = 'name';
$handler->display->display_options['style_options']['data_fields'] = array(
  'field_gender' => 'field_gender',
  'name' => 0,
  'field_age' => 0,
  'created' => 0,
);
$handler->display->display_options['style_options']['field_colors'] = array(
  'name' => '#2f7ed8',
  'field_age' => '#0d233a',
  'field_gender' => '#8bbc21',
  'created' => '#910000',
);
$handler->display->display_options['style_options']['title_position'] = 'in';
$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_title'] = 'custom lallalalala ';
$handler->display->display_options['style_options']['yaxis_labels_rotation'] = '0';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['link_to_user'] = FALSE;
/* Field: User: Age */
$handler->display->display_options['fields']['field_age']['id'] = 'field_age';
$handler->display->display_options['fields']['field_age']['table'] = 'field_data_field_age';
$handler->display->display_options['fields']['field_age']['field'] = 'field_age';
$handler->display->display_options['fields']['field_age']['settings'] = array(
  'thousand_separator' => '',
  'prefix_suffix' => 0,
);
/* Field: User: Gender */
$handler->display->display_options['fields']['field_gender']['id'] = 'field_gender';
$handler->display->display_options['fields']['field_gender']['table'] = 'field_data_field_gender';
$handler->display->display_options['fields']['field_gender']['field'] = 'field_gender';
$handler->display->display_options['fields']['field_gender']['type'] = 'list_key';
/* Field: User: Created date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'users';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['date_format'] = 'short';
/* 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;

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'chart';
bennos’s picture

StatusFileSize
new29.12 KB

attched my config.

bennos’s picture

My first idead was "the SQL is wrong", but this is ok.
So I looked in the module a little bit.
Sorry here, I am not good in views coding.

charts_plugin_style_chart.inc filling the data array begins at line 152

you get the data by the $field_handler array.
this contains the unique ID.
But what I not see is $field->content array or $field->raw
to get the data from the field or something similiar from $row

greets bennos

quicksketch’s picture

StatusFileSize
new1.69 KB

Thanks @skyredwang for the confirmation. I suspect the problem here is that Drupal saves a value of "0" for unchecked checkboxes:

$handler->display->display_options['style_options']['data_fields'] = array(
  'field_gender' => 'field_gender',
  'name' => 0,
  'field_age' => 0,
  'created' => 0,
);

The format that is expected by the Views handler is shorter:

$handler->display->display_options['style_options']['data_fields'] = array(
  'field_gender' => 'field_gender',
);

So I think all we need to do is run array_filter() on the options and the unexpected ones will be trimmed out. Could you guys try this patch and see if it helps?

quicksketch’s picture

Priority: Critical » Normal
Status: Active » Fixed

I've committed this patch as it seems to solve the problem. Please reopen if you're still experiencing the problem where the wrong field is being used to provide data.

quicksketch’s picture

Title: ID is used and not the field value » Unchecked fields for "data" sources incorrectly included in chart rendering
quicksketch’s picture

Title: Unchecked fields for "data" sources incorrectly included in chart rendering » ID is used and not the field value

After reproducing #2051807: Notice: Undefined index: #type in charts_pre_render_element(), it looks like this issue is not solved. Incidentally, *that* problem may have been solved by my patch in #6, but the current problem still remains: User IDs are being used instead of the actual data.

Now it looks like this problem originates from using entity-based values. Charts module is reading the raw value from SQL queries when it builds its values. In the case of queries where data is not actually retrieved from a SQL query, but instead from fully-loaded entities, the data structure is different.

bennos’s picture

Title: ID is used and not the field value » Unchecked fields for "data" sources incorrectly included in chart rendering
Priority: Normal » Major
Status: Fixed » Needs work

For me the patch does not work.
patch applied and cleared all caches.

My data points still have the wrong value.
It is not the field value in the chart. The chart still uses the ID for the data point.

quicksketch’s picture

StatusFileSize
new3.43 KB

Okay I think this patch should fix the problem. As I said in #9, "entity-based values" (or "entity-based field values" more accurately) are formatted in a way that requires additional effort. After looking at the Table display style some, it looks like in order to work with field values we need to render everything in the view all at once, then then loop through the rendered results. Previously we were just using the raw values or rendering a field one at a time.

quicksketch’s picture

Title: Unchecked fields for "data" sources incorrectly included in chart rendering » ID instead of value is used for values pulled from entity-based fields
Status: Needs work » Fixed

I think this patch has fixed the problem. I'll make a new beta for testing.

quicksketch’s picture

2.0-beta3 is now available which should make Charts' integration with field-based values work well in Views.

bennos’s picture

works

great! thx quicksketch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.