Skip to content

Instantly share code, notes, and snippets.

@tux89
Last active September 8, 2016 01:20
Show Gist options
  • Save tux89/357b9ef186deb96e4c8eb6285ffc37ba to your computer and use it in GitHub Desktop.
Save tux89/357b9ef186deb96e4c8eb6285ffc37ba to your computer and use it in GitHub Desktop.

Line chart with label

var chart = c3.generate({
    data: {
        x: 'x',
        columns: [
            ['x', '2013-10-31', '2013-12-31', '2014-01-31', '2014-02-28'],
            ['sample', 30, 80, 110, 110],
        ],
        labels: {
            format: {
                sample: function (v, id, i, j) {
                    if (v > 100)
                        return ""
                    return ""; 
                },
            }
        },
        onmouseover: function (d) { 
            d.value = "xxxx";
        }
    },
    grid: {
        y: {
            lines: [
                {value: 100, text: 'Abunai'}
            ]
        }
    },
    axis : {
        x : {
            type : 'timeseries',
            tick: {
                fit: true,
                format: "%e %b %y"
            }
        },
        y: {
            min: 0,
            max: 100,
            padding: {top: 40, bottom:0},
            tick: {
                format: function (d) { 
                    if (d > 100)
                        return 'over';
                    else
                        return d;
                }
            }
        }
    }
});
@tux89
Copy link
Author

tux89 commented Sep 8, 2016

  • Init graph
  • Load data
  • Fix data
  • Update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment