如何为甜甜圈 c3.js 图表的标题添加样式

How can I add style to title of donut c3.js chart

任何人都可以建议我为 C3.js 圆环图的标题添加样式的方法吗?

对于任何甜甜圈 c3 图表,是否有设置 title 样式的选项?

我将这段代码用于我的圆环图。

var chart = c3.generate({
        data: {
            columns: [
                ['Monday', 70],
                ['TuesDay', 20],
                ['Wednesday', 30],
                ['Thursday', 50],
                ['Friday', 100]
            ],
            type: 'donut'
        },
        donut: {
            title: "Usage " // How to do? style("color", "#59C2E6")
        }
    });

甜甜圈 title 通过渲染使用 class c3-chart-arcs-title

您可以只覆盖 c3-chart-arcs-title 样式。你的代码应该是这样的:

.c3-chart-arcs-title {
  fill: red;
  font-size: 16px;
}

只需覆盖 .c3-chart-arcs-title 样式 class 的填充 属性,像这样:

 <html>
  <head>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/c3/0.4.5/c3.min.css" />
  </head>
  <body>
    <div id="chart"></div>

    <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
    <script src="http://c3js.org/js/c3.min-12912fb6.js"></script>

 <style>
   .c3-chart-arcs-title {
                         fill: #59C2E6;
                        }
</style>
    <script>
   var chart = c3.generate({
        data: {
            columns: [
                ['Monday', 70],
                ['TuesDay', 20],
                ['Wednesday', 30],
                ['Thursday', 50],
                ['Friday', 100]
            ],
            type: 'donut'
        },
        donut: {
            title: "Usage " // How to do? style("color", "#59C2E6")

        }
    });
      setTimeout(function () {
        chart.axis.labels({
          x: 'New X Axis Label',
          y: 'New Y Axis Label',
          y2: 'New Y2 Axis Label',
        });
      }, 1000);
      setTimeout(function () {
        chart.load({
          columns: [
            ['data1', 100, 300, 600, 200, 400, 500]
          ]
        });
        chart.axis.labels({y: 'New Y Axis Label Again'});
      }, 2000);
    </script>
  </body>
</html>