public function graphConfig()
{
if (!isset($this->series[0]['data'])) {
$data = $this->dataSet();
} else {
$data = $this->series[0]['data'];
}
$totalEyes = 0;
$plusOrMinusOne = 0;
$plusOrMinusHalf = 0;
$plusOrMinusHalfPercent = 0;
$plusOrMinusOnePercent = 0;
foreach ($data as $dataRow) {
$totalEyes += (int) $dataRow[1];
// 19 and 21 are the indexes of the -0.5 and +0.5 columns
if ($dataRow[0] < 19 || $dataRow[0] > 21) {
$plusOrMinusHalf += (int) $dataRow[1];
}
// 18 and 22 are the indexes of the -1 and +1 columns
if ($dataRow[0] < 18 || $dataRow[0] > 22) {
$plusOrMinusOne += (int) $dataRow[1];
}
}
if ($plusOrMinusOne > 0) {
$plusOrMinusOnePercent = number_format($plusOrMinusOne / $totalEyes * 100, 1, '.', '');
}
if ($plusOrMinusHalf > 0) {
$plusOrMinusHalfPercent = number_format($plusOrMinusHalf / $totalEyes * 100, 1, '.', '');
}
$this->graphConfig['subtitle']['text'] = str_replace(array('{{eyes}}', '{{0.5}}', '{{1}}'), array($totalEyes, $plusOrMinusHalfPercent, $plusOrMinusOnePercent), $this->graphConfig['subtitle']['text']);
$this->graphConfig['chart']['renderTo'] = $this->graphId();
return json_encode(array_merge_recursive($this->globalGraphConfig, $this->graphConfig));
}