Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart X-Axis tick limiting #67

Closed
CHR15- opened this issue Mar 13, 2014 · 10 comments
Closed

Chart X-Axis tick limiting #67

CHR15- opened this issue Mar 13, 2014 · 10 comments
Labels
C-bug Category: This is a bug C-feature-request Category: A feature request or an enhancement question resolved maybe

Comments

@CHR15-
Copy link

CHR15- commented Mar 13, 2014

Hi,

Is it possible to set the number of items in the x axis at a given time? for example.. currently for the chart, the x axis contains the same amount of values..:

Small screen size
screen shot 2014-03-13 at 18 50 45

Medium screen size
screen shot 2014-03-13 at 18 50 25

Large screen size
screen shot 2014-03-13 at 18 50 55

Regardless of the chart size, there is 7 items on the x-axis... is there an option in the API to limit this such as:

axis: {
x: {
values: 3
}
}

this would produce the following:

screen shot 2014-03-13 at 18 56 31

axis: {
x: {
values: 5
}
}

would produce the following:

screen shot 2014-03-13 at 18 57 29

@masayuki0812
Copy link
Member

You can use axis.x.tick.count option like axis.x.tick.count = 5.
Sample is here - http://c3js.org/samples/axes_x_tick_count.html
Please try this.
Thanks.

@CHR15-
Copy link
Author

CHR15- commented Mar 14, 2014

ok, understand this.. but is there a way to change it while the chart is in the page.. ie, dynamically load it?

chart.load({
axis: {
x: {
tick: {
count : 20
}..

@JakeSidSmith
Copy link

Would be great if we could pass a function to the tick.count so it would update automatically .e.g

tick: {
  count: function () {
    return chart.size.width / 10;
  }
}

Also, the tick.count seems to be a little buggy at the moment. When this is set to certain values it draws a different number of ticks.

e.g.
tick.count = 4, actually draws 7
tick.count = 3, actually draws 2

@CHR15-
Copy link
Author

CHR15- commented Mar 18, 2014

@masayuki0812

http://jsfiddle.net/e482V/8/ is an example where count is ignored when set to 5.
http://jsfiddle.net/e482V/9/ is an example where 3 is set but 2 is in the chart.
http://jsfiddle.net/e482V/10/ is where 4 is set, only 2 in the chart

if you set 5... it no longer listens to count

@masayuki0812
Copy link
Member

Thank you for your troubleshooting, but it might be not easy to fix this because c3 uses d3 native function to set tick count..
Anyway, I'll check about this more.

@JakeSidSmith Hi, I agree with your idea. I'll add that functionality later.

@CHR15-
Copy link
Author

CHR15- commented Mar 31, 2014

@masayuki0812 Any news on this one?

@masayuki0812
Copy link
Member

Sorry, there is not, but I'm considering to use categorized axis. I'll try later.

masayuki0812 added a commit that referenced this issue Apr 4, 2014
@masayuki0812
Copy link
Member

@chris-Opsimize I think this has been fixed and could you try on the latest version 0.1.27?

@CHR15-
Copy link
Author

CHR15- commented Apr 4, 2014

Looks grand!

@CHR15- CHR15- closed this as completed Apr 4, 2014
@raghbendra2015
Copy link

raghbendra2015 commented Jun 28, 2017

@masayuki0812

I am facing one issue in X axis values. See my code below

<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="c3.js"></script>
<script>
var chart = c3.generate({
    data: {
        x : 'x',
        columns: [
            ['x', 'Ho Chi Minh City', 'Tanjung Priok (Jakarta)', 'Shenzhen', 'Haiphong', 'Antwerp', 'Chennai', 'Memphis Rail Ramp', 'Los Angeles / Long Beach / San Pedro', 'Shanghai', 'Shanghai'],
            ['Your lowest rate', 30, 200, 100, 400, 300, 25, 1000, 40000,20000,23000],
            ['Benchmark rate', 400, 200, 100, 4000, 1900, 100, 1400, 250,16000,19000],
            ['Lowest rate on route', 350, 15000, 19000, 16210, 16000, 12040, 12510, 18800,19500,11150],
        ],
        type: 'bar'
    },
    axis: {
        x: {
            type: 'category' // this needed to load string x value
        },
        y: {
          label: {
            text: 'Your Y Axis',
            position: 'outer-middle'
          },

        tick: {
          values: [1000, 5000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000]
        }

        }
    },

graph

});

I have used "Shanghai" at two places in X axis value. Now its showing the position of Shanghai in array not name when I am plotting the graph. See attached graph image. How can I show the duplicate name in X - axis ..... because in my case there can be duplicate records in X- axis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug C-feature-request Category: A feature request or an enhancement question resolved maybe
Projects
None yet
Development

No branches or pull requests

4 participants