javascriptd3.jsc3.js

C3.js tootltip font


I was trying this example in `c3js.

Demo

Does anyone know how to increase the font size of the Tooltip contents (both title and value)?

Any help would be appreciated.


Solution

  • Override the font value for the following selectors:

    .c3-tooltip th {
      /* for the header */
    }
    
    .c3-tooltip td.name {
      /* for the title cells */
    }
    
    .c3-tooltip td.value {
      /* for the value cells */
    }
    

    EXAMPLE

    var chart = c3.generate({
        data: {
            columns: [
                ['data1', 30000, 20000, 10000, 40000, 15000, 250000],
                ['data2', 100, 200, 100, 40, 150, 250]
            ],
            axes: {
                data2: 'y2'
            }
        },
        axis : {
            y : {
                tick: {
                    format: d3.format("s")
                }
            },
            y2: {
                show: true,
                tick: {
                    format: d3.format("$")
                }
            }
        },
        tooltip: {
            format: {
                title: function (d) { return 'Data ' + d; },
                value: function (value, ratio, id) {
                    var format = id === 'data1' ? d3.format(',') : d3.format('$');
                    return format(value);
                }
    //            value: d3.format(',') // apply this format to both y and y2
            }
        }
    });
    .c3-tooltip th {
      /* for the header */
      color: red !important;
    }
    
    .c3-tooltip td.name {
      /* for the title cells */
      color: green;
    }
    
    .c3-tooltip td.value {
      /* for the value cells */
      color: blue;
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.12/c3.min.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.12/c3.min.js"></script>
    <div id='chart'></div>