Yii2 : 手图扩展标签格式化程序用法



我正在尝试利用Yii2 Flot扩展,或多或少取得了成功。但是,我在使用 labelFormatter 函数更改饼图的标签时遇到问题。

这是我正在使用的扩展名:bburim/flot

这是我到目前为止的代码,它生成了一个漂亮的图表,但我无法更改标签。 任何帮助,不胜感激。

echo Chart::widget(
[
'data' => [
['label' => 'Series1', 'data' => [1, 12]],
['label' => 'Series2', 'data' => [1, 16]],
['label' => 'Series3', 'data' => [1, 89]],
['label' => 'Series4', 'data' => [1, 44]],
['label' => 'Series5', 'data' => [1, 38]],
],
'options' => [
'series' => [
'pie' => [
'show' => true,
'label' => [
'show' => true,
'treshold' => 0.1,
'radius' => 0.6,
'value' => 'value',
],
],
],
'grid' => [
'hoverable' => true,
],
'legend' => [
'position' => 'nw',
'show' => true,
'font' => [
'size' => 16,
],
'margin' => 10,
'backgroundOpacity' => 0.5,
],
],
'plugins' => [
Plugin::PIE,
],
'htmlOptions' => [
'class' => 'chartdiv',
],
]
);

这是一个相当宽泛的术语,可以说自定义,我会假设它意味着提供自定义标签文本,它非常简单明了,您只需要使用回调函数的new JsExpression()即可正常工作

echo Chart::widget(
[
'data' => [
['label' => 'Series1', 'data' => [1, 12]],
['label' => 'Series2', 'data' => [1, 16]],
['label' => 'Series3', 'data' => [1, 89]],
['label' => 'Series4', 'data' => [1, 44]],
['label' => 'Series5', 'data' => [1, 38]],
],
'options' => [
'series' => [
'pie' => [
'show' => true,
'label' => [
'show' => true,
'treshold' => 0.1,
'radius' => 0.6,
'value' => 'value',
],
],
],
'grid' => [
'hoverable' => true,
],
'legend' => [
'labelFormatter' => new JsExpression("function(label, series) {
// series is the series object for the label
return '<a href="#' + label + '">Custom Label for '+series.label+'</a>';
}"),
'position' => 'nw',
'show' => true,
'font' => [
'size' => 16,
],
'margin' => 10,
'backgroundOpacity' => 0.5,
],
],
'plugins' => [
Plugin::PIE,
],
'htmlOptions' => [
'class' => 'chartdiv',
],
]
);

附带说明一下,我不会使用该存储库,因为自 2015 年以来所有者似乎没有响应,没有关于这些问题的单一回复,您可能需要自己维护或修复错误,以便更好地分叉存储库并使用您自己的自定义版本

最新更新