【问题标题】:Apexcharts - Label colours do not matchApexcharts - 标签颜色不匹配
【发布时间】:2020-05-29 15:10:20
【问题描述】:

我为标签指定了三种不同的颜色,但颜色点始终显示为蓝色、绿色和黄色。我很确定我做错了什么。

我写的代码是:

var pieSimpleChart = {
  chart: {
    height: 350,
    type: 'pie',
  },
  legend: {
    position: 'bottom'
  },
  labels: ["IT", "Product Development", "Sales"],
  series: [2, 2, 6],
  fill: {
    colors: ["#447b40", "#cc7870", "#e74ce4"]
  }
}

var chart = new ApexCharts(document.querySelector("#task-pie-chart"), pieSimpleChart);
chart.render();

如何将标签与我选择的颜色相匹配?

【问题讨论】:

    标签: apexcharts


    【解决方案1】:

    我通过删除“填充”选项来修复它。 现在代码看起来像:

        var pieSimpleChart = 
        {
            chart: 
            {
                height: 350,
                type: 'pie',
            },
            legend: 
            {
                position: 'bottom'
            },
            labels: ["IT", "Product Development", "Sales"],
            series: [2, 2, 6],
            colors: ["#447b40", "#cc7870", "#e74ce4"]
        }
    

    【讨论】:

    【解决方案2】:

    使用backgroundColor 代替fill: colors

    另外,您应该使用dataset 对象来传递值:

    var ctx = document.getElementById("myChart").getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'pie',
        data: {
            labels: ["IT", "Product Development", "Sales"],
            datasets: [{
                backgroundColor: [
                    "#ff0000",
                    "#00ff00",
                    "#0000ff"
                ],
                data: [2, 2, 6]
            }]
        },
        options: {
            legend: {
                position: 'bottom'
            }
        }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.js"></script>
    <div class="container">
      <div>
        <canvas id="myChart"></canvas>
      </div>
    </div>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    相关资源
    最近更新 更多