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(&$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:
<?php
function benim_hook_chart_alter(&$chart, $chart_id) {
if ($chart_id === 'chartim__block_1') {
// Individual properties may be modified.
$chart['#title_font_size'] = 50;
$chart['subtitle'] = array(
'#text' => 'Source:',
);
$chart['xaxis'] = array(
'#type' => 'chart_xaxis',
'#allowDecimals' => 'true',
);
}
}
function benim_hook_chart_definition_alter(&$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(&$chart, $chart_id) {
if ($chart_id === 'chartim__page') {
// Individual properties may be modified.
$chart['#title_font_size'] = 150;
$chart['subtitle'] = array(
'#text' => 'Source:',
);
$chart['xaxis'] = array(
'#type' => 'chart_xaxis',
'#allowDecimals' => 'false',
);
$chart['yaxis'] = array(
'#type' => 'chart_yaxis',
'#allowDecimals' => 'false',
);
}
}
function mytheme_hook_chart_definition_alter(&$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.
benim_hook_chart_alter()
orbenim_chart_alter()
; therefore, you cannot change the question's code. As for code shown by the OP, the full question is based on a typo; that is why the question got closed: "This question was caused by a problem that can no longer be reproduced, was solved by a cache clear, or was a simple typographical error."