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

Show x labels #897

Closed
wants to merge 3 commits into from
Closed

Show x labels #897

wants to merge 3 commits into from

Conversation

hay-wire
Copy link

Applicable to bar chart and line chart.

User can now pass a { showXLabels: 10 } to display only 10 labels (actual displayed labels count might be a bit different depending on the number of total labels present on x axis, but it will still remain close to 10 however)

Helps a lot when there is a very large amount of data. Earlier, the graph used to look devastated due to x axis labels drawn over each other in the cramped space. With showXLabels, user now has the control to reduce the number of labels to whatever number of labels fit good into the space available to him.

Please see the attached images for a comparison. the second graph has been passed { showXLabels: 10 } into option.

Without showXLabels:
without showXLabels: crowded

With showXLabels = 10:
with showXLabels: 10

Usage: Just pass showXLabels: 10 along with other options in the constructor.
Example:
myLine = new Chart(ctx).Line(lineChartData, {
responsive: true,
showXLabels: 10
});

@adrianandreias
Copy link

Labels rendering angle is calculated as if all (let's say) 100 labels are rendered, though when rendering showXLabels: 5 there's enough space to render them horizontally:

chartjs

@hay-wire
Copy link
Author

@adrianandreias No it doesn't do that. I tried once though, but couldn't figure out the code which handles label rotation. Maybe I would try it again and update here in a while.

@etimberg
Copy link
Member

@hay-wire can you remove Chart.js and Chart.min.js from your PR? It's easier for us to merge that way.

@beaucharman
Copy link

+1 :D

@edz504
Copy link

edz504 commented Jan 29, 2015

+1 def need this

@seanadkinson
Copy link

+1

@hay-wire
Copy link
Author

@etimberg I'm not sure how to do that in the current branch as the current PR already contains built files (Chart.js and Chart.min.js)! Can you please guide me a bit?

@hay-wire
Copy link
Author

okay I'm making changes in showXLabels with a cleaner history, latest pull from nnick's repo and no changes to Chart.js or Chart.min.js.
Will force push after finishing and update here. Do not pull until my next comment! :-p

Apologies for this mess. I'm not very acquainted with PRs. This is my first time.

It enables controlling how many labels should be shown on x axis. Really helpful in case there are huge number of labels.

Chart.Core.js has been edited  so, showXLabels option is available to any other chart as well if anybody wants to extend this feature.
Until now all ticks have been painted which does not makes sense if you have thousands of values and only want to show 10. the svg path for the tick mark is now only painted if the corresponding value is also painted. thanks for your fork!

---
This commit is on behalf of @gerbsen <https://github.com/gerbsen> who had submitted this patch for an older branch (which I had messed up). Thanks gerbsen.
@hay-wire
Copy link
Author

@etimberg : I force updated showXLabels branch with cleaner history. Chart.js and Chart.min.js have not been affected. Hope this one works. Let me know if I need to resubmit a fresh PR.

@hay-wire
Copy link
Author

@adrianandreias I tried fixing label rotation again yesterday. However, as of now, it is tightly coupled with all available xLabels. Even if I do it, then label rotation would become dependent on showXLabels, which is more of a hack than a good solution as @nnnick pointed out earlier.

So leaving it for now. I'll try if I can take showXLabels more closer to what nnnick had proposed. That might take care of label rotation as well.

@fulldecent
Copy link
Contributor

There is discussion going on as to whether this is the best approach to the problem. Tagging Potential

@jakesylvestre
Copy link
Contributor

+1 for merge, this looks like a good solution, but I agree that there may be a better one

@bryceadams
Copy link

how's the discussion going with this?

@hay-wire
Copy link
Author

I dont see any progress in this regard. All the PRs are pending.. https://github.com/nnnick/Chart.js/labels/Potential

Maybe the team is working on a cleaner solution.

@flimshaw
Copy link

+1!

@ooghry
Copy link

ooghry commented Feb 22, 2015

+1

@akougblenou
Copy link

Has feature been finally merged or is it still pending ?

@jakesylvestre
Copy link
Contributor

I think we can merge... any objections?

@fulldecent
Copy link
Contributor

Objection. Can we please merge this to a feature or dev branch? We have been discussing several fixes to axis labeling and settling on one prevents us from trying another.

@hay-wire
Copy link
Author

@jakesyl : I second @fulldecent .

@akougblenou
Copy link

So it has been finally merged then ?

@harscoet
Copy link

harscoet commented May 7, 2015

@hay-wire Is-it possible to add your fork on bower and merge regularly with the master ? Because I'm not sure this feature will be available one day in the master...

@jonasva
Copy link

jonasva commented May 11, 2015

+1
Very common requirement to have the x-axis intervals autoscale. Hope we can get a solution for this.

@hay-wire
Copy link
Author

@harscoet: I haven't ever done that. Let me give it a try and come back to you. Any links in this regard would be appreciated.

@harscoet
Copy link

@hay-wire Fist step you should update the Chart.js and Chart.min.js with gulp

npm install;gulp

For bower you have some info in this post http://stackoverflow.com/questions/25104623/how-to-properly-register-a-github-fork-with-bower

@jonathan-s
Copy link

+1 for merging.

@jeduan
Copy link

jeduan commented May 26, 2015

👍

@aneeshd16
Copy link

+1. This is needed!

@peruzzo
Copy link

peruzzo commented Jun 19, 2015

+1

@cklemming
Copy link

+1! Definitely needed.

@gibolocopt
Copy link

+1

4 similar comments
@tartavull
Copy link

+1

@patramsey
Copy link

+1

@albertpak
Copy link

👍

@coxley
Copy link

coxley commented Jul 31, 2015

+1

@TBSliver
Copy link

TBSliver commented Aug 4, 2015

Hi, is there any progress on getting this feature merged? or if there is another (undocumented) feature which does this? Looks like this has been stalled since January, and unless there are actual hard objections to this I see no reason why it is not already in.

@tannerlinsley
Copy link
Contributor

There is now an auto-magic feature for x-label spacing, rotation, and skipping in v2.0-dev (alpha). It's very young, but in line with the way we are handling scales in the next version. Take a look at the v2.0-dev branch examples to test!

We plan to add plenty of customization features in this area very soon, but for now having a solution that will be responsive, and automatic for most use cases is our goal.

@tannerlinsley
Copy link
Contributor

We've recently announced a feature complete status for v1.x and will only be accepting bug fixes for v1.x. Be sure to take a look at v2.0-dev and it's new features that are either finished or currently under development. If you see your feature is still not implemented, feel free to submit another PR to the v2.0-dev (or later) branch for your feature.

@va-h
Copy link

va-h commented Jan 31, 2016

Any update which branch to use now to get this feature?

@kovalevsky
Copy link

kovalevsky commented May 25, 2016

Didn't merged yet?

@JimmyVT
Copy link

JimmyVT commented Nov 4, 2016

+1 Hi ! Are there any updates on this?

@dtturcotte
Copy link

Is this merged in yet?

@patrickml
Copy link

Any updates?

@vjoao
Copy link

vjoao commented Jul 23, 2018

Any updates on this matter?

@Septimis
Copy link

It looks like ChartJS does this now
https://www.chartjs.org/docs/latest/samples/scale-options/ticks.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.