如何为donut c3.js图表​​的标题添加样式

时间:2016-01-09 07:30:25

标签: javascript c3.js

任何人都可以建议我在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")
        }
    });

2 个答案:

答案 0 :(得分:4)

Donut title通过渲染使用类c3-chart-arcs-title

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

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

答案 1 :(得分:0)

只需覆盖.c3-chart-arcs-title样式类的fill属性,如下所示:

 <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>