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

Styling LinearScale needs full config of axis #11

Open
benweidig opened this issue Nov 2, 2017 · 2 comments
Open

Styling LinearScale needs full config of axis #11

benweidig opened this issue Nov 2, 2017 · 2 comments
Assignees

Comments

@benweidig
Copy link

benweidig commented Nov 2, 2017

Hi,

I'm trying to style a linear scale (just fontStyle and fontColor) of a LineChart:

LinearTicks ticks = new LinearTicks().setFontStyle(FontStyle.BOLD);
LinearScale axis = new LinearScale().setTicks(ticks);
LinearScales scales = new LinearScales().addxAxis(axis)
LineOptions options = new LineOptions().setScales(scales);

The problem is that the LinearScale always puts the property type: "linear" into the the tick config, and chartjs then wants me to configure all the other stuff for the ticks/scale and no data is displayed if not.

If I remove the the property from the chart JSON config object before initializing the Chart with delete json.options.scales.xAxes[0].type it's formating as expected.

Workaround for me was creating a class TypelessLinearScale extends LinearScale with @JsonIgnore on an overriden getType().

Not sure how to handle this problem "nicely", a type-less Scale would be nice, but setOptions(...) on LineOptions needs a LinearScale and not a Scale<?> or something.

@benweidig benweidig changed the title Styling LinearAxis needs full config of axis Styling LinearScale needs full config of axis Nov 2, 2017
@mdewilde mdewilde self-assigned this Nov 14, 2017
mdewilde added a commit that referenced this issue Nov 14, 2017
@mdewilde
Copy link
Owner

Unfortunate issue, and nice of you to let me know.
To resolve this, I was thinking of adding a custom serializer, that adds the type depending on some condition.
However, at this point, I'm not entirely sure as to when adding the type will cause the chart to not be displayed.
I've added a basic test to begin debugging the issue: https://github.com/mdewilde/chart/blob/58fb9147d436a42eca9f4472cc0051982716d9b7/src/test/java/be/ceau/chart/tests/TypelessLinearScaleTest.java

If you have any input on the issue, or any more info on which specific configurations trigger the problem, please do let me know.

@benweidig
Copy link
Author

Sorry for the late reply...

I looked around in the chart.js repo and found this issue (chartjs/Chart.js#4687) and it seems that "I'm holding it wrong" and should have used a category axis

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

No branches or pull requests

2 participants