Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Colors Jqplot饼图/圆环图系列颜色数组未重复使用/重复_Colors_Jqplot_Reusability_Series_Donut Chart - Fatal编程技术网

Colors Jqplot饼图/圆环图系列颜色数组未重复使用/重复

Colors Jqplot饼图/圆环图系列颜色数组未重复使用/重复,colors,jqplot,reusability,series,donut-chart,Colors,Jqplot,Reusability,Series,Donut Chart,我正在使用jqplot绘制饼图和甜甜圈图。 我使用“系列颜色”为切片提供定制颜色 系列颜色:[“0571B0”、“5E3C99”、“008837”] 如果数据(要传递的数组值)只有三个值,那么它会正确显示颜色。 但如果有3个以上的值,它只会以黑色显示该切片。 它不会从一开始就重复/重用颜色(如文档中所述) 这是: var s2 = [['a', 8], ['b', 12], ['c', 6]]; var plot1 = $.jqplot('div_1', [s2], {

我正在使用jqplot绘制饼图和甜甜圈图。 我使用“系列颜色”为切片提供定制颜色

系列颜色:[“0571B0”、“5E3C99”、“008837”]

如果数据(要传递的数组值)只有三个值,那么它会正确显示颜色。 但如果有3个以上的值,它只会以黑色显示该切片。 它不会从一开始就重复/重用颜色(如文档中所述)

这是:

var s2 = [['a', 8], ['b', 12], ['c', 6]];
var plot1 = $.jqplot('div_1', [s2], {
                title: 'Chart 1',

                seriesDefaults:{
                  renderer:$.jqplot.DonutRenderer ,
                  rendererOptions:{
                        startAngle: -90,
                        innerDiameter: 100,
                        showDataLabels: true,
                        dataLabels:'percent'
                     }
                    },
                    seriesColors: ["#0571B0", "#5E3C99", "#008837"],
                    highlighter: {
                        show: true
                    },
                    legend: { show:true, rendererOptions: {numberRows: 1}, location: 's', placement: 'outsideGrid'}
                });
但是,如果我在数组中添加第四个值,则不会重用颜色。 i、 如果我将上述数组修改为

var s2 = [['a', 8], ['b', 12], ['c', 6], ['d', 9]];
然后,第四个切片(“d”)以黑色显示

如何修复此问题?

找到了此问题的修复方法。 希望这能帮助其他面临类似问题的人

这是密码

var dataValues = [['a', 8], ['b', 12], ['c', 6], ['d', 9], ['e', 14]];

//Define the seriesColors array..
var seriesColors = ["#0571B0", "#5E3C99", "#008837"];

var seriesColorsLength = seriesColors.length;
var donutChartSeriesColors = new Array();

//Prepare a new array which would be passe to the chart..
//This will handle even if there are more value than the seriesColors array..
for(var i = 0; i < dataValues.length; i++) {
donutChartSeriesColors[i] = seriesColors[(seriesColorsLength-1) % i];
}

var plot1 = $.jqplot('div_1', [dataValues ], {
            title: 'Chart 1',

            seriesDefaults:{
              renderer:$.jqplot.DonutRenderer ,
              rendererOptions:{
                    startAngle: -90,
                    innerDiameter: 100,
                    showDataLabels: true,
                    dataLabels:'percent'
                 }
                },
                seriesColors: donutChartSeries,
                highlighter: {
                    show: true
                }
});
var-dataValues=[[a',8],[b',12],[c',6],[d',9],[e',14];
//定义序列颜色数组。。
变量系列颜色=[“#0571B0”、“#5E3C99”、“#008837”];
var seriesColors length=seriesColors.length;
var donutChartSeriesColors=新数组();
//准备一个新数组,该数组将传递到图表中。。
//即使存在比SeriesColor数组更多的值,也会处理此问题。。
对于(var i=0;i