PrimeFaces PolarArea图表-GridLine颜色更改

时间:2019-03-12 08:18:23

标签: javascript charts primefaces chart.js jqplot

我的应用程序中有一个p:polarAreaChart图表,并且将 Primefaces primefaces-7.0.RC1与JSF2一起使用

我想更改每个圆的线条颜色(GridLine)。我已经尝试了以下代码,但是根本没有用。

gridLines.setDisplay(true);

gridLines.setColor("rgb(255, 255, 255)");

gridLines.setLineWidth(10);

radialScales.setGridLines(gridLines);

options.setScales(radialScales);

polarAreaMode.setOptions(options);

请让我知道我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

看来您可以轻松做到。请参见以下示例:https://www.chartjs.org/samples/latest/charts/polar-area.html

并在该页面的视图源中使用“ backgroundColor”:

        var randomScalingFactor = function() {
            return Math.round(Math.random() * 100);
        };

        var chartColors = window.chartColors;
        var color = Chart.helpers.color;
        var config = {
            data: {
                datasets: [{
                    data: [
                        randomScalingFactor(),
                        randomScalingFactor(),
                        randomScalingFactor(),
                        randomScalingFactor(),
                        randomScalingFactor(),
                    ],
                    backgroundColor: [
                        color(chartColors.red).alpha(0.5).rgbString(),
                        color(chartColors.orange).alpha(0.5).rgbString(),
                        color(chartColors.yellow).alpha(0.5).rgbString(),
                        color(chartColors.green).alpha(0.5).rgbString(),
                        color(chartColors.blue).alpha(0.5).rgbString(),
                    ],
                    label: 'My dataset' // for legend
                }],
                labels: [
                    'Red',
                    'Orange',
                    'Yellow',
                    'Green',
                    'Blue'
                ]
            },
            options: {
                responsive: true,
                legend: {
                    position: 'right',
                },
                title: {
                    display: true,
                    text: 'Chart.js Polar Area Chart'
                },
                scale: {
                    ticks: {
                        beginAtZero: true
                    },
                    reverse: false
                },
                animation: {
                    animateRotate: false,
                    animateScale: true
                }
            }
        };

然后查看PolarAreaChart的PrimeFaces源代码,我看到BackgroundColor接受了一个字符串列表,即RGB字符串。

public class PolarAreaChartDataSet extends ChartDataSet {

    private static final long serialVersionUID = 1L;

    private List<Number> data;
    private List<String> backgroundColor;
    private List<String> borderColor;
    private List<Number> borderWidth;
    private List<String> hoverBackgroundColor;
    private List<String> hoverBorderColor;
    private List<Number> hoverBorderWidth;