本文整理汇总了PHP中ezcGraphRenderer::drawPieSegment方法的典型用法代码示例。如果您正苦于以下问题:PHP ezcGraphRenderer::drawPieSegment方法的具体用法?PHP ezcGraphRenderer::drawPieSegment怎么用?PHP ezcGraphRenderer::drawPieSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ezcGraphRenderer
的用法示例。
在下文中一共展示了ezcGraphRenderer::drawPieSegment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderData
/**
* Render the assigned data
*
* Will renderer all charts data in the remaining boundings after drawing
* all other chart elements. The data will be rendered depending on the
* settings in the dataset.
*
* @param ezcGraphRenderer $renderer Renderer
* @param ezcGraphBoundings $boundings Remaining boundings
* @return void
*/
protected function renderData(ezcGraphRenderer $renderer, ezcGraphBoundings $boundings)
{
// Only draw the first (and only) dataset
$dataset = $this->data->rewind();
$datasetName = $this->data->key();
$this->driver->options->font = $this->options->font;
// Calculate sum of all values to be able to calculate percentage
$sum = 0;
foreach ($dataset as $name => $value) {
if ($value < 0) {
throw new ezcGraphInvalidDataException("Values >= 0 required, '{$name}' => '{$value}'.");
}
$sum += $value;
}
if ($this->options->sum !== false) {
$sum = max($sum, $this->options->sum);
}
if ($sum <= 0) {
throw new ezcGraphInvalidDataException("Pie charts require a value sum > 0, your value: '{$sum}'.");
}
$angle = 0;
foreach ($dataset as $label => $value) {
// Skip rendering values which equals 0
if ($value <= 0) {
continue;
}
switch ($dataset->displayType->default) {
case ezcGraph::PIE:
$displayLabel = $this->options->labelCallback !== null ? call_user_func($this->options->labelCallback, $label, $value, $value / $sum) : sprintf($this->options->label, $label, $value, $value / $sum * 100);
$renderer->drawPieSegment($boundings, new ezcGraphContext($datasetName, $label, $dataset->url[$label]), $dataset->color[$label], $angle, $angle += $value / $sum * 360, $displayLabel, $dataset->highlight[$label]);
break;
default:
throw new ezcGraphInvalidDisplayTypeException($dataset->displayType->default);
break;
}
}
}