jquery 更改顶点图中单个条形的颜色

ddarikpa  于 2022-11-03  发布在  jQuery
关注(0)|答案(3)|浏览(166)

更改顶点图中的条形图时遇到问题。该图表是混合图表(折线图/条形图)。我想更改单个条形图的颜色。
我尝试过的解决方案是,按照apex图表文档在www.example.com中添加一个fillColorseries.data,但它不起作用。
图表对齐enter image description here
这是我的代码。
响应.设备.数据.值AND响应.流量计.值是一个数值数组。

if (newChart !== null) {
                newChart.destroy();
            }

            var options = {
                chart: {
                    height: 350,
                    stacked: false,
                    height: '400',
                    toolbar: {
                        tools: {
                            download: true,
                            selection: false,
                            zoom: false,
                            zoomin: false,
                            zoomout: false,
                            pan: false,
                            reset: false,
                            customIcons: []
                        }
                    }
                },
                dataLabels: {
                    enabled: false
                },
                stroke: {
                    width: [2, 1],
                    curve: 'stepline'
                },
                yaxis: [
                    {
                        axisTicks: {
                            show: true,
                        },
                        axisBorder: {
                            show: true,
                            color: '#008FFB'
                        },
                        labels: {
                            style: {
                                color: '#008FFB',
                            }
                        },
                        title: {
                            text: "<?=_('Device(s)')?> (m3)",
                            style: {
                                color: '#008FFB'
                            }
                        },
                        tooltip: {
                            enabled: true
                        }
                    },
                    {
                        opposite: true,
                        axisTicks: {
                            show: true,
                        },
                        axisBorder: {
                            show: true,
                            color: '#00E396'
                        },
                        labels: {
                            style: {
                                color: '#00E396',
                            }
                        },
                        title: {
                            text: "<?=_('Flowmeter(s)')?> (m3)",
                            style: {
                                color: '#00E396',
                            }
                        }
                    },
                ],
                tooltip: {
                    followCursor: true,
                },
                legend: {
                    horizontalAlign: 'center',
                    offsetX: 40
                },
                zoom: {
                    enabled: false
                },

                xaxis: {
                    categories: response.device.data.labels,
                    labels: {
                        style: {
                            fontSize: '10px'
                        }
                    }
                },
                series: [
                    {
                        name: '<?=_('Device(s)')?>',
                        type: 'line',
                        data: response.device.data.values
                    },
                    {
                        name: '<?=_('Flowmeter(s)')?>',
                        type: 'bar',
                        data: response.flowmeter.values
                    }
                ],

            };

            newChart = new ApexCharts(document.querySelector("#new-chart"), options);
            newChart.render();
xkftehaa

xkftehaa1#

你可以在系列的对象中设置颜色属性。比如:

series: [
                {
                    name: '<?=_('Device(s)')?>',
                    type: 'line',
                    color: "00FA9A",
                    data: response.device.data.values
                },
                {
                    name: '<?=_('Flowmeter(s)')?>',
                    type: 'bar',
                    color: "#F44336",
                    data: response.flowmeter.values
                }
            ],
xcitsw88

xcitsw882#

您可能会使用传递函数到fill属性。请检查此链接:https://apexcharts.com/docs/options/fill/。您也可以根据序列索引进行自订。

flvlnr44

flvlnr443#

colors: [function({ value, seriesIndex, w }) {
  return colors(value)
}],

function colors(id) {
  var colors = [
    "#33b2df",
    "#546E7A",
    "#d4526e",
    "#13d8aa",
    "#A5978B",
    "#2b908f",
    "#f9a3a4",
    "#90ee7e",
    "#f48024",
    "#69d2e7"
  ];
  return colors[id] ?? '#33b2df';
}

相关问题