为类别 Highcharts 小部件中的任何元素创建 link
create link for any element in categories Highcharts widget
我在视图 yii2 中使用了 Highcharts 小部件 project.I 想为条形图(Highcharts 小部件)上的类别标签创建 URL,在我的代码中可以使用粗体标签并且标签是粗体但是当添加 href 标签时我有没有 link.
如何在 xAxis 类别中创建 href link?
<?php
$x = array("a", "b", "c");
$y = array_values(array(4, 2, 6));
echo Highcharts::widget([
'options' => [
'chart' => [
'type' => 'column',
'zoomType' => 'x',
],
'title' => [
'text' => 'Project chart',
],
'xAxis' => [
'categories' => $x,
'labels' => [
'formatter' => new JsExpression('function(){ return "<a href=hghgh><b>"+this.value+" bgbgbg</b></a>"; }')
],
'useHTML'=> 'true'
],
'yAxis' => [
'title' => [
'text' => 'Count',
],
],
'series' => [
[
'type' => 'column',
'name' => 'p1',
'data' => $y,
],
],
]
]);
?>
您需要注意的几件事
- 您正在使用
options
选项,而您应该使用 clientOptions
(如果您正在使用此小部件,我想 https://github.com/2amigos/yii2-highcharts-widget)
- 您在错误的地方使用了
useHtml
它应该在 labels
选项下而不是 categories
,您还应该将 boolean
传递给 useHtml
表示没有引号 true
应该被传递。
您的完整代码应如下所示
<?php
use yii\web\JsExpression;
use dosamigos\highcharts\HighCharts;
$x = array("a", "b", "c");
$y = array_values(array(4, 2, 6));
echo HighCharts::widget([
'clientOptions' => [
'chart' => [
'type' => 'column',
'zoomType' => 'x',
],
'title' => [
'text' => 'Project chart',
],
'xAxis' => [
'categories' => $x,
'labels' => [
'formatter' => new JsExpression('function(){ return "<a href=hghgh><b>"+this.value+" bgbgbg</b></a>"; }'),
'useHTML' => true,
],
],
'yAxis' => [
'title' => [
'text' => 'Count',
],
],
'series' => [
[
'type' => 'column',
'name' => 'p1',
'data' => $y,
],
],
],
]);
我在视图 yii2 中使用了 Highcharts 小部件 project.I 想为条形图(Highcharts 小部件)上的类别标签创建 URL,在我的代码中可以使用粗体标签并且标签是粗体但是当添加 href 标签时我有没有 link.
如何在 xAxis 类别中创建 href link?
<?php
$x = array("a", "b", "c");
$y = array_values(array(4, 2, 6));
echo Highcharts::widget([
'options' => [
'chart' => [
'type' => 'column',
'zoomType' => 'x',
],
'title' => [
'text' => 'Project chart',
],
'xAxis' => [
'categories' => $x,
'labels' => [
'formatter' => new JsExpression('function(){ return "<a href=hghgh><b>"+this.value+" bgbgbg</b></a>"; }')
],
'useHTML'=> 'true'
],
'yAxis' => [
'title' => [
'text' => 'Count',
],
],
'series' => [
[
'type' => 'column',
'name' => 'p1',
'data' => $y,
],
],
]
]);
?>
您需要注意的几件事
- 您正在使用
options
选项,而您应该使用clientOptions
(如果您正在使用此小部件,我想 https://github.com/2amigos/yii2-highcharts-widget) - 您在错误的地方使用了
useHtml
它应该在labels
选项下而不是categories
,您还应该将boolean
传递给useHtml
表示没有引号true
应该被传递。
您的完整代码应如下所示
<?php
use yii\web\JsExpression;
use dosamigos\highcharts\HighCharts;
$x = array("a", "b", "c");
$y = array_values(array(4, 2, 6));
echo HighCharts::widget([
'clientOptions' => [
'chart' => [
'type' => 'column',
'zoomType' => 'x',
],
'title' => [
'text' => 'Project chart',
],
'xAxis' => [
'categories' => $x,
'labels' => [
'formatter' => new JsExpression('function(){ return "<a href=hghgh><b>"+this.value+" bgbgbg</b></a>"; }'),
'useHTML' => true,
],
],
'yAxis' => [
'title' => [
'text' => 'Count',
],
],
'series' => [
[
'type' => 'column',
'name' => 'p1',
'data' => $y,
],
],
],
]);