How can I add a title to c3.js chart
Asked Answered
M

4

18

Can any one suggest me the way of adding title to the C3.js line and bar charts ? I have got the following sample but it is for gauge chart. For any c3 chart is there any option to set the chart title?

donut: {
  title: 'Title'
}
Menology answered 23/2, 2015 at 5:59 Comment(0)
K
9

You'd need to fall back to using D3 to add a chart title. Something like:

d3.select("svg").append("text")
    .attr("x", 100 )
    .attr("y", 50)
    .style("text-anchor", "middle")
    .text("Your chart title goes here");
Kieserite answered 23/2, 2015 at 11:27 Comment(0)
S
55

This was a top google result, so I thought I'd add that this is now part of the library:

title: {
  text: 'My Title'
}

More info @ https://github.com/masayuki0812/c3/pull/1025

Southeastward answered 4/2, 2016 at 17:10 Comment(3)
Note: requires version 0.4.11Chancemedley
Working PerfectlyEulalie
And about alignment? (middle/left/rigth)Venditti
K
9

You'd need to fall back to using D3 to add a chart title. Something like:

d3.select("svg").append("text")
    .attr("x", 100 )
    .attr("y", 50)
    .style("text-anchor", "middle")
    .text("Your chart title goes here");
Kieserite answered 23/2, 2015 at 11:27 Comment(0)
P
5

I am using this code for my chart.

Code:

var chart = c3.generate({
        data: {
            columns: [
                ['Monday', 70],
                ['TuesDay', 20],
                ['Wednesday', 30],
                ['Thursday', 50],
                ['Friday', 100]
            ],
            type: 'donut'
        },
        donut: {
            title: "usage "
        }
    });

Result :

Result of my code

Pipette answered 3/8, 2015 at 11:46 Comment(0)
U
3

also couldn't find a way and ended up writing the title as the unit and editing the label.

gauge: {
        label: {
            format: function(value, ratio) {
                return "%"+value;
            },
            show: true // to turn off the min/max labels.
        },
    min: 0, 
    max: 100, 
    units: "Overall Profit"
//    width: 39 // for adjusting arc thickness
    },
Ursal answered 19/4, 2015 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.