Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Top Right Legend Position for a C3 chart?

Tags:

c3.js

Is there a way to position the legend in 'top right' for c3 charts?

The current options appear to only allow 'bottom' and 'right'. I've noticed there is a 'Custom Legend Option'. However, I wanted to check before proceeding down this path.

Thanks

like image 833
Mark Collins Avatar asked Nov 11 '14 23:11

Mark Collins


People also ask

How do I change the position of my legend in a graph?

Click the chart, and then click the Chart Design tab. Click Add Chart Element > Legend. To change the position of the legend, choose Right, Top, Left, or Bottom. To change the format of the legend, click More Legend Options, and then make the format changes that you want.

What is c3 chart?

c3 is a D3-based reusable chart library that enables deeper integration of charts into web applications. Follow the link for more information: http://c3js.org.


1 Answers

I have a same issue. So I spent many time to find the solution. And Finally, I got the solution. Here is the solution.

Document

C3 Document is not bad, but some example is incomplete. Position of legend is one of them.

The example show position of legend can be located in only bottom, right and inset. That's all. But in the document, you can find more possibility.

Look at the c3.legend.position in the document. The document says again legend can be located in only bottom, right and inset. But don't be disappointed. Look at the below item, c3.legend.inset. And today, that item will save our time.

Code

First of all, look at the example.

legend: {
  inset: {
    anchor: 'top-right'
    x: 20,
    y: 10,
    step: 2
  }
}

You see it? That's a top-right you want. And code works wonderfully. If you change anchor, the position of legend'll be changed. And you can adjust coordinates with x and y. And step may be adjust length of legend. If you increase it, then legend'll be longer. But it's my guess. Please someone explain more about it.

Example

Here is my example.

c3.legend.inset example

var appActivityChart = c3.generate({
    data: {
        //...
    },
    legend: {
        show: true,
        position: 'inset',
        inset: {
            anchor: 'top-right',
            x: 250,
            y: 50,
            step: 5
        }
    }
});

I hope C3 add or refer about c3.legend.inset. Current example is too complicated. Until that time I hope this answer can save your time. Have great coding.

like image 133
Penguin Avatar answered Jan 30 '23 02:01

Penguin