It would be handy to be able to push more data onto the point object passed down to Highcharts. My use case is as follows:

1. I'm rendering my chart in custom code
2. I only care about Pie Charts
3. I want to put entirely custom text into the tooltip for individual pie slices (which is not the same as the point Label/name, which I *do* need because I want it to be the label for the slice).

Now Highcharts allows me to embed variables into tooltip.pointFormat, so all I need to do is get something custom added onto the point object.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jamsilver’s picture

Assigned: jamsilver » Unassigned
Status: Needs work » Needs review
FileSize
732 bytes

I've attached a patch which simply allows a #description property on 'charts_data_item' elements.

Now my solution, in full is:

// Code which builds chart up contains:
$chart['pie_data'][] = array(
  '#type' => 'chart_data_item',
  '#title' => 'Label',
  '#description' => 'Tooltip contents',
  '#data' => 'Value',
);

// Then later we can implement an alter to tell Highcharts to use this variable:

/**
 * Implements hook_chart_definition_alter().
 */
function MYMODULE_chart_definition_alter(&$chart_definition, &$element, $chart_id) {
  if (!empty($chart_definition['tooltip']['pointFormat'])) {
    $chart_definition['tooltip']['pointFormat'] = '{point.description}';
  }
}
quicksketch’s picture

Status: Needs review » Needs work

Hi @jamsilver, thanks for this request. As with other requests for "Add X feature to Y library", we can't add functionality that doesn't have some equivalent in both supported libraries. If this functionality can be added to Google Charts as well, I'll be happy to add it. Otherwise, perhaps this request should be wrapped into #2209467: Google Charts only: Pass library-specific options via existing #raw_options, where you'd be allowed to pass library-specific options into various settings.

Pierre.Vriens’s picture

Title: Add an extra #description to data items (for Highcharts) for better tooltips. » Add an extra #description to data items for better tooltips.
Parent issue: » #2209467: Google Charts only: Pass library-specific options via existing #raw_options
Anonymous’s picture

Note: i editted this comment after i discovered that highcharts were not working correctly for me.

I am trying to get tooltips to work for scatter charts and found this issue. I think the suggestions in #2 and #3 are not required.

Google supports the "data point" concept as well. And the current Google interface module has code to support the concept. HINT: Look for chart_data_item in the drupal code. The only thing lacking is something in charts_plugin_style_chart.inc

I was able to pass tooltips to google charts by picking off a field value and stuffing it into the $chart in charts_plugin_style_chart.inc

$chart[$series_key][] = array(
'#type' => 'chart_data_item',
'#title' => $label,
);

The #title value becomes the tooltip displayed by both google. The highcharts specific patch above can be generalized into picking up the tooltip from the #title?