How to set properties for a specific chart only using the views integration of the Charts module? I'm creating charts using the charts module and its integration with the Views module.

I want to set options for only some charts and found that in charts.api.php:

/**
 * Alter an individual chart before it is printed.
 *
 * @param $chart
 *   The chart renderable. Passed in by reference.
 * @param $chart_id
 *   The chart identifier, pulled from the $chart['#chart_id'] property (if
 *   any). Not all charts have a chart identifier.
 */
function hook_chart_alter(&amp;$chart, $chart_id) {
  if ($chart_id === 'view_name__display_name') {
    // Individual properties may be modified.
    $chart['#title_font_size'] = 20;
  }
}


It seems perfect for what I want because it has the if ($chart_id === 'view_name__display_name') { line for specific views but I wonder if I directly add some settings code such as $chart['#title_font_size'] = 10; here (to charts.api.php) or is there any other way to do this?

I mean overriding the charts.api.php inside of the charts module is OK or do I have to write and run these codes anywhere else?

EDIT:

Based on rooby's comments, these are the two ways that I tried to set the properties for each charts (created with views module):


1. Custom Module


I created a custom module called benim.

This is the benim.info file:

name = Benim
description = Override charts properties.
package = Other
core = 7.x


And this is the benim.module file:

&lt;?php

function benim_hook_chart_alter(&amp;$chart, $chart_id) {
  if ($chart_id === 'chartim__block_1') {
    // Individual properties may be modified.
    $chart['#title_font_size'] = 50;
    $chart['subtitle'] = array(
    '#text' =&gt; 'Source:',
    );
    $chart['xaxis'] = array(
    '#type' =&gt; 'chart_xaxis',
    '#allowDecimals' =&gt; 'true',

    );

  }
}



function benim_hook_chart_definition_alter(&amp;$definition, $chart, $chart_id) {
  if ($chart['#chart_library'] === 'highcharts') {
  if ($chart_id === 'chartim__block_1') {
    $definition['title']['style']['fontSize'] = 100;
  }
}
}



2. Template.php


I added the lines below to the theme's template.php.

function mytheme_hook_chart_alter(&amp;$chart, $chart_id) {
  if ($chart_id === 'chartim__page') {
    // Individual properties may be modified.
    $chart['#title_font_size'] = 150;
    $chart['subtitle'] = array(
    '#text' =&gt; 'Source:',
    );
    $chart['xaxis'] = array(
    '#type' =&gt; 'chart_xaxis',
    '#allowDecimals' =&gt; 'false',

    );

    $chart['yaxis'] = array(
    '#type' =&gt; 'chart_yaxis',
    '#allowDecimals' =&gt; 'false',

    );

  }
}

function mytheme_hook_chart_definition_alter(&amp;$definition, $chart, $chart_id) {
  if ($chart['#chart_library'] === 'highcharts') {
  if ($chart_id === 'chartim__page') {
    $definition['title']['style']['fontSize'] = 100;
  }
}
}


(above mytheme is the name of the actual theme)

Unfortunately, both two ways didn't work for me. I wondered if the $chart_id parameter is correct and checked for different views but the result didn't change.

Note: I also tried clearing caches, and trying inside another theme.
No, not in the charts module, in a custom module of your own.

It is also possible for you to use drupal alter hooks from your theme's template.php file however you should be careful what you put in your theme.
You should only put code relating to visuals in the theme, if you are doing more functional code it should go in a module.

A good rule of thumb is whether or not you would want to keep that functionality if you ever changed themes. If you would want to keep it then that is a possible indicator that it is functional, not visual, and should be in a module.

.api.php files are files that give developers information on the function and hooks that a module makes available to others. 

It is basically just documentation so you editing it will do nothing (except for then making that documentation incorrect, which is bad if anyone else wants to use it).

Some reasons why it is generally not a good idea to modify the module itself can be found at Why don&#39;t we hack core? (it is talking about drupal core but the same goes for other contrib modules and themes).
One of the main reasons we have drupal hooks is so you don't have to modify the original module if you want to make changes.

So you would create a custom drupal module and then in that module implement the hook like this (changing MODULENAME to the name of the module and the chart ID to match the ID of your specific chart):

/**
 * Alter an individual chart before it is printed.
 *
 * @param $chart
 *   The chart renderable. Passed in by reference.
 * @param $chart_id
 *   The chart identifier, pulled from the $chart['#chart_id'] property (if
 *   any). Not all charts have a chart identifier.
 */
function MODULENAME_chart_alter(&amp;$chart, $chart_id) {
  if ($chart_id === 'view_name__display_name') {
    // Individual properties may be modified.
    $chart['#title_font_size'] = 20;
  }
}


There are lots of other drupal module development resources besides drupal.org docs too. There are some good affordable textbooks and some paid training type websites, as well as a scattering of blog posts in random corners of the internet.

Here is a more functional example of using the definition alter hook.

/**
 * Alter an individual chart's raw library representation.
 *
 * This hook is called AFTER hook_chart_alter(), after Charts module has
 * converted the renderable into the chart definition that will be used by the
 * library. Note that the structure of $definition will differ based on the
 * charting library used. Switching charting libraries may cause your code
 * to break when using this hook.
 *
 * Even though this hook may be fragile, it may provide developers with access
 * to library-specific functionality.
 *
 * @param $definition
 *   The chart definition to be modified. The raw values are passed directly to
 *   the charting library.
 * @param $chart
 *   The chart renderable. This may be used for reference (or read to add
 *   support for new properties), but any changes to this variable will not
 *   have an effect on output.
 * @param $chart_id
 *   The chart ID, derived from the $chart['#chart_id'] property. Note that not
 *   all charts may have a $chart_id.
 */
function THEMENAME_chart_definition_alter(&amp;$definition, $chart, $chart_id) {
  // For the portfolio charts.
  if ($chart_id == 'MY_CHART_ID') {
    $definition['legend']['borderRadius'] = 0;
    $definition['legend']['borderColor'] = NULL;
    $definition['legend']['style']['fontFamily'] = 'Helvetica,Arial,"Nimbus Sans L",sans-serif';
    $definition['legend']['backgroundColor'] = 'transparent';
    $definition['legend']['layout'] = 'vertical';
    $definition['legend']['verticalAlign'] = 'top';
    $definition['legend']['padding'] = 0;
    $definition['legend']['margin'] = 0;
    $definition['legend']['itemStyle']['color'] = '#555555';
    $definition['legend']['itemStyle']['fontSize'] = '12px';
  }
}