如何使用 PrimeFaces 设置 ChartJS 轴标签
How to set ChartJS Axis label with PrimeFaces
我正在使用 ChartJS 附带的 PrimeFaces 7。
可以选择将 title/label 添加到图表本身以及数据集。但是,我找不到将 titles/labels 添加到轴的方法。也没有关于如何在展示柜上做到这一点的例子:https://www.primefaces.org/showcase/ui/chartjs/
我尝试使用扩展函数,就像我们在旧版本的 PF 中使用旧的 JQPlot 一样。所以在 JS 函数上,我正在尝试配置标签,如下所示:https://www.chartjs.org/docs/latest/axes/labelling.html
所以看起来像这样:
xhtml:
<script>
function extender() {
if (!this.cfg.config.options) {
this.cfg.config.options = {}
}
var options = $.extend(true, {}, this.cfg.config.options);
options = {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'test'
}
}],
xAxes: [{
scaleLabel: {
display: true,
labelString: 'test'
}
}],
}
};
$.extend(true, this.cfg.config, options);
};
</script>
Java豆子:
barModel = new BarChartModel();
barModel.setExtender("extender");
并且:未显示任何标签。
我是不是漏掉了什么?
我的 JS 函数不正确。下面的代码现在按预期工作:正在显示 y 轴标签。
function extender1() {
var options = {
options: {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Order amount'
}
}],
}
}
};
$.extend(true, this.cfg.config, options);
};
我正在使用 ChartJS 附带的 PrimeFaces 7。
可以选择将 title/label 添加到图表本身以及数据集。但是,我找不到将 titles/labels 添加到轴的方法。也没有关于如何在展示柜上做到这一点的例子:https://www.primefaces.org/showcase/ui/chartjs/
我尝试使用扩展函数,就像我们在旧版本的 PF 中使用旧的 JQPlot 一样。所以在 JS 函数上,我正在尝试配置标签,如下所示:https://www.chartjs.org/docs/latest/axes/labelling.html
所以看起来像这样:
xhtml:
<script>
function extender() {
if (!this.cfg.config.options) {
this.cfg.config.options = {}
}
var options = $.extend(true, {}, this.cfg.config.options);
options = {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'test'
}
}],
xAxes: [{
scaleLabel: {
display: true,
labelString: 'test'
}
}],
}
};
$.extend(true, this.cfg.config, options);
};
</script>
Java豆子:
barModel = new BarChartModel();
barModel.setExtender("extender");
并且:未显示任何标签。
我是不是漏掉了什么?
我的 JS 函数不正确。下面的代码现在按预期工作:正在显示 y 轴标签。
function extender1() {
var options = {
options: {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Order amount'
}
}],
}
}
};
$.extend(true, this.cfg.config, options);
};