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

Ability to give line graph X values a string description #121

Closed
jentfoo opened this issue Dec 23, 2015 · 13 comments
Closed

Ability to give line graph X values a string description #121

jentfoo opened this issue Dec 23, 2015 · 13 comments

Comments

@jentfoo
Copy link
Contributor

jentfoo commented Dec 23, 2015

I think this is a feature request more than anything. I have a need to be able to provide String descriptions for points along the X graph, ideally not even showing the numbers.

A couple thoughts on how to do this would be a possible type that extends Number, constructed with a numeric value, and a String which is gathered from .toString(). Then place those .toString() values on the X axis where they belong.

In theory the same thing can be done with dates as well.

Let me know your thoughts, if you have ideas on how this could be done easiest, if I have time I could provide a PR.

@jentfoo
Copy link
Contributor Author

jentfoo commented Dec 23, 2015

Another (maybe better?) way to accomplish what I need would be to allow a String series for line graphs. Assume each string is just a distance of 1 from the previous one. Then on the X axis just display those strings.

@timmolter
Copy link
Member

@jentfoo After thinking about this, I don't like the idea of extending Number or A String series. However, I think what would work is to create another Bar Chart type, where instead of bars, points and lines are drawn.

So perhaps the solution is to change the Bar Chart into a Category Chart, and be able to set the series type, bar being the default. Then everything is the same except right at the end when the data is drawn, it just checks what to draw and draws either bars or lines, etc.

@jentfoo
Copy link
Contributor Author

jentfoo commented Dec 25, 2015

Seems resonable. Any idea how much effort it will be? Will the bar graph drawing be able to easily share the line drawing code of the line graphs??

@timmolter
Copy link
Member

Should be around 30 minutes to an hour of coding and testing.

I don't think it will be easily able to share. Maybe you could make a SeriesDrawer class with static methods to draw the various series types. Otherwise copypasta it, and I can clean it up later.

jentfoo added a commit to jentfoo/XChart that referenced this issue Dec 29, 2015
Adds a new type "category" which is a line graph, but with labels for the x axis rather than scaled numerical values.
This is to resolve knowm#121, but still has a few issues.

Originally I copied PlotContentLineChart into a new PlotContentCategoryChart, but instead found that with just a few extra conditionals could allow for a large amount of reuse code.

There is still an issue where the angle points of the line graph still don't line up right with the X axis lines.

The "category" type does have a few restrictions:
  * Setting a min and max X axis value has no effect
  * Setting the X axis to be log has no effect
  * When providing data series the X data points must always match, missing data points for a given series is not currently handled
@timmolter
Copy link
Member

See BarChart09. Let me know if that works for you.

@jentfoo
Copy link
Contributor Author

jentfoo commented Dec 30, 2015

@timmolter I can make that work. A few considerations with this style:

  • If you want the lines to all match the x axis you need to "chart.getStyleManager().setBarWidthPercentage(0)". Otherwise it seems the lines are staggered based off a now invisible bar width. Seems like a kind of awkward hidden detail. Maybe this should be automatically set with that style?
  • The y axis values are no longer automatically scaled. As you can see in my latest version, the y axis minimum is auto scaled to to be relative to the dataset.
    priorityschedulerexecute

With your new design the same graph looks like:
priorityschedulerexecute

Is there a way to get the same Y axis scaling? I hate to have to put the logic into my apps, but I can if necessary.

@jentfoo
Copy link
Contributor Author

jentfoo commented Dec 30, 2015

Also, I do think the X axis lines/grid sometimes makes the graph easier to read. Is it possible to get those back? If not, it's not a huge deal breaker, but I thought I would at least point it out as another difference.

It does seem like the line graph design is more of a natural fit for displaying this data?

@timmolter
Copy link
Member

@jentfoo all valid points! I'll work on it. Could you submit a PR, with your above plot code? I'd like to use it to create this new feature and add it to my demo.

@timmolter
Copy link
Member

If you want the lines to all match the x axis you need to "chart.getStyleManager().setBarWidthPercentage(0)". Otherwise it seems the lines are staggered based off a now invisible bar width. Seems like a kind of awkward hidden detail. Maybe this should be automatically set with that style?

I don't see what you mean. Can you show me some how?

@timmolter
Copy link
Member

Please try the latest code and run LineChart07.

@jentfoo
Copy link
Contributor Author

jentfoo commented Jan 4, 2016

@timmolter I just took a look. It looks like it's working fine for my needs! I thought I would point out that the logarithmic setting you have enabled in the demo is causing the Y axis to not draw at all. But as soon as you disable that, it looks great!

Would you like me to open a new issue for that (knowing it's not important to me, but may be to others)?

@timmolter
Copy link
Member

No, I'll just fix it. Eventually soonish.

@timmolter
Copy link
Member

Closing. Logarithmic axes doesn't even make sense for this plot. My bad.

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 a pull request may close this issue.

2 participants