Skip to content

Line chart with String X-Axis data, starting closer to Y-Axis #267

@ghost

Description

I'm trying to make a line chart with String values in the X-Axis.
XYChart doesn't work because "Series data must be either Number or Date type" (as an exception message told me).
So I tried to use a CategoryChart with line rendering (as in your example).
This way it works, but the offset of the line's starting point is a bit too large for my taste.
This is how it looks:
actual
And this is what I'd like:
expected
I checked the API and also did some debugging, and there seems to be no way to configure this.
I found the xOffset variable in:
org.knowm.xchart.internal.chartpart.PlotContent_Category_Line_Area_Scatter.doPaint(Graphics2D)
As far as I can tell, we always add half a gridStep at the beginning.

If you don't have time for that, I would try to change this myself and then send a pull request, but I'd like your opinion.

  1. Should we try and alter the aforementioned part of the code (PlotContent_Category_Line_Area_Scatter)? Maybe that half gridStep makes sense for bar charts, but for lines maybe it could be different.
  2. Should we change the XYChart to accept Strings for the X-Axis? I'm thinking of using the index of the String array for the values, and the actual String only as a label.

Which variant makes more sense to you?

Or do you see another way of doing it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions