-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Line Chart - Data series without label for each point #12
Comments
Yes, or chart.js should have a way to hide data points based on width, kind of what like google charts does. For instance, displaying data for Jan 1-30, but the graph is only x pixels wide, it shows Jan 1-30, but skips every other date. |
@humdedum That is a pretty stupid comment. There is nothing wrong with feature enhancements, they should not be taken negatively, but positively by people being interested in @nnnick's projects. It gives him a good idea of what to improve for his users. I plan on trying to contribute to this project, and reading some of these issues/feature enhancements gives me a good idea of what other people are thinking as well. As for using "" as a label, that might work right now, but I am sure user interaction/tooltips will come soon, and that will not work when displaying default tooltip information. |
@humdedum I was suggesting decoupling x axis labels from data points because for a line chart, I imagine a greater percentage of use cases not requiring labels for each point than those that do. It seems inefficient from that regard. Since the project is young, I am trying to raise thought rather than rush to find a workaround. |
@humdedum but this suggestion will definitely improve this project. People pull data from databases all the time to draw these charts and the last thing they want to do is have to determine which labels stay and which labels go. For example, if I pull an integer column for my data points and a date column for my labels in the database, I'm not going to want to have to filter out those date columns based on the width of the canvas and the number of points on my chart. Not everyone creates static HTML pages. " :-)". |
i added a skipLabels option on .Line |
@r043v Looks good. Did you ever form a PR for that? |
@r043v This is definitely a welcome improvement, but how is skipLabels used? Adding "skipLabels : [int]" as an option does not make any change to the line chart or it's labels. Maybe I misunderstood your idea, documentation about it would be helpful. |
Line charts are simply indexed across the x axis, so they need a label for each point. A potentially better solution would be to create a |
Is there an open issue for creating such "Series" chart? |
Not as of yet, it is something I made a very brief start on in the past though. I think it should probably live in it's own repo rather than this repo, so perhaps creating an issue here isn't the best idea. That way there could be alternate community run variants etc. |
@humdedum I feel like you're missing the entire point of open source software. If contributors were silenced and "good enough" was accepted as the norm, we'd still be using Linus Torvald's (wonderful at the time) Linux 1.0. Hell, Github wouldn't even have a reason for existing. As I'm dealing with very large numbers of data points (500+), a graphing library that requires labels is unusable as shown by @hay-wire's first graph above. I love the look of this library, and may try my hand at a PR as well. |
@loganfuller you can use skip-xlabels branch from my fork of Chart.js with showXLabels option: |
I think this isn't the right solution to this problem. The line charts in Chart.js are designed to handle index data, so just skipping the render of certain labels feels like a hacky solution. What I propose as a better solution would be to define an x/y value for a point, then have Chart.js dynamically generate the x scale, similar to how the y scale is generated dynamically currently. It'd require data in slightly different format, so that's why I propose another chart type for this. I think a lot of the base classes for points/bars/whatever could be reused, with an extension to/a new scale class providing this dynamic x/y functionality. What do you guys think? |
If you want to hide the labels when there are too many, you can use the following extension. It just pushes the x-labels off the canvas so they are painted but not visible.
|
Love this chart.js. How can I configure it so the label is alway on by default without hovering it? |
There is a great hack here. I quote: For concreteness, let's say your original list of labels looks like:
If you only want to display every 4th label, filter your list of labels so that every 4th label is filled in, and all others are the empty string (e.g. |
@nnnick, any news on this feature? I think a lot of people need it as it's pretty common to have a lot of data on your x-axis. |
👍 i need this too |
Very interested in this feature. I have a a graph I need to create with 1,000+ points across X. Do I use one of the hacked modules or is this coming into the main branch? Thanks for great software! |
I'm using |
The problem with using |
This is google analytics line chart. as you can see all the days are not labeled in the x axis but the data of each day is in the line chart, and if you hover on each Dot a tooltip will show the date & the Y value. Thanks again for your great project. |
And can you skip labels altogether? On Thursday, November 27, 2014, Sören Schwert notifications@github.com
King Harrison IV Executive Vice President |
@r043v how do you use your skipLabels option? I'm also interested in this! |
Fully agree with @nnnick that a Scale is the right solution and not a skip labels option to avoid chart.js growing to complex. |
I created a gist that shows how to implement a series chart. The implementation is not perfect but working! https://gist.github.com/saintedlama/05cc1663f3e38e06e2d7 |
@etimberg, how do I specify the number of displayed X labels? |
@ehajri We don't have a hard count on the number of labels. If you use a line chart in v2.0 it should behave exactly as a line chart in v1.0. We created the scatter chart that has a different x axis which dynamically adjusts the number of labels (not user settable at the moment). At the moment the x axis of the scatter chart only supports numerical data. We're going to write a date/time scale before 2.0 releases but it has not been done yet, What kind of labels do you have? In the v2.0 config you can specify a user callback for each axis as config: {
scales: {
xAxes: [{
labels: {
userCallback: function(tickValue, index, tickArray) { return "label string"},
}
}],
}
} You could return an empty string for no label. Does this help? Can you create a jsfiddle of your use case and I can try and give some better advice. |
Guys It was sa irritating I did it using two solutions and adding my hack ;)
Replace With: if(this.showXLabels === true || this.showXLabels === false) Now pass the option: showXLabels, to get requested nr of labels! Or you can leave it false and it works original way |
The following snippet will hide labels automatically. By modify
Please notice that |
Any ideas when v2 will be out with this feature? |
v2.0-dev already has multiple ways of achieving this. Primarily, there is a built in auto-skip feature that will reduce labels as they overlap in most circumstances. You can also override the labels via a userCallback function that is used in the core scale class, or even override the entire scale.ticks array with whatever you want in a hook function. We're working on documentation for these new features right now. |
how?? |
For those who are trying to get rid of the x-axis labels altogether, while retaining y-axis labels, I was able to achieve this with the following:
|
Any word on where the documentation for this can be found? |
Can you make the x axis time / date data with a scatter chart? I don't see anything in the docs about it. |
+1, docs pls |
If it's of any help, I get the desired effect of reducing the numbers of objects in the X label by adding the following line:
Where X is the padding you want between the values (and it will create an empty space accordingly), try adjusting the X value so it suits your needs. |
+1 It's a shame this feature request has been around for so long and nothing has been done. |
@gentisaliu this is supported in v2 out of the box. See https://github.com/chartjs/Chart.js/blob/master/samples/scatter.html |
Thanks, I missed that. I tested it and it works, however is there a way to control the number of displayed labels/ticks in the X axis? I want to display for instance at most 4 labels in the X axis, since any more than that they overlap and they get difficult to read. |
Awesome job and thank you all. Is this also supported on bar charts for a series of dates? I can't seem to make this work. |
This question is now a couple of years old. Is there in the current version a better solution to achieve this? I can not seem to make this work. Or is there some documentation where I can find this? |
What is the exact question? This is quite a thread with many questions/answers. As for the original question, you have a lot of control over labels in v2.x.x. Check out the callbacks in the scales documentation, |
Use highcharts. i ended up doing the same. |
I have the same problem. I am creating a chart by dynamically assigning value to both labels and dataset. But at certain point, label are not showing. label data is generating but not showing. |
The use case I'm having (and I don't really see solved with any of the mentioned changes), is the following: I have a dataset of 255 data samples. On my X axis though I only want to show 0%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 100% as the labels. And, obviously, these labels don't really match an exact sample in my data array. They're somewhere in between. E.g. 0% = 0, 10% = 25.5, etc. The simplest solution would be if chart.js would not match the labels with the samples in case of a line chart, but simply would draw the lines and then draw the labels independently below the chart. E.g. it would help if I could simply specify: and chart.js would automatically divide the labels linearly through the data instead of matching them to the first three samples in my data. |
+1 Like so: |
A good solution would be if each data-point could be an object or array and contain an optional label Example:
Or somesuch. |
@george-viaud you need close expression with |
From the Line Chart documentation,
"The line chart requires an array of labels for each of the data points. This is show on the X axis."
I would like to be able to add a large set of data points to a line chart, but not have a label for each data point. For instance, showing the months of the year on the x axis but having several data points between January and February. I know the project is young, but would you agree this is a good direction to go? I feel the x axis labels and data set should be decoupled.
The text was updated successfully, but these errors were encountered: