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

Removing space before and after chart #388

Open
ibrahimatcha opened this issue Nov 21, 2023 · 8 comments
Open

Removing space before and after chart #388

ibrahimatcha opened this issue Nov 21, 2023 · 8 comments

Comments

@ibrahimatcha
Copy link

ibrahimatcha commented Nov 21, 2023

Hi,

I am using a CategoryDataset to produce a bar chart which is then being rendered using a LineAndShapeRenderer to appear as a line chart. I'm having an issue where I cannot find a way to remove the gaps before and after the chart! I want it so that the first value sits on the y-axis and the last value sits on the edge of the graph. Please advise how I can get rid of the space marked by the black squiggly lines.

Screenshot 2023-11-21 at 11 50 12
@ibrahimatcha
Copy link
Author

ibrahimatcha commented Nov 21, 2023

CategoryDataset dataset = DatasetUtils.createCategoryDataset("Data", data);
JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.VERTICAL, false, false, false);
LineAndShapeRenderer renderer = new LineAndShapeRenderer();

    CategoryPlot categoryPlot = (CategoryPlot) chart.getPlot();
    categoryPlot.setRenderer(renderer);

    ValueAxis yAxis3 = categoryPlot.getRangeAxis();
    TickUnits tickUnits = new TickUnits();
    tickUnits.add(new NumberTickUnit(10000));
    yAxis3.setStandardTickUnits(tickUnits);

    yAxis3.setUpperBound(Math.round(yAxis3.getUpperBound()/10000) * 10000);`

@ibrahimatcha
Copy link
Author

My markup didn't format properly ;(

@trashgod
Copy link
Contributor

What happens if you adjust the lower and upper margins of your CategoryAxis?

@ibrahimatcha
Copy link
Author

ibrahimatcha commented Nov 21, 2023

Unfortunately adding xAxis.setLowerMargin(0); xAxis.setUpperMargin(0); results in the same result
Screenshot 2023-11-21 at 12 58 42

NOTE: This is the same chart, just done a bunch of styling

@trashgod
Copy link
Contributor

What happens if you specify a negative value for the lower and upper margins of your CategoryAxis?

domainAxis.setLowerMargin(-0.05);
domainAxis.setUpperMargin(-0.05);

@ibrahimatcha
Copy link
Author

Using a negative margin produced the desired effect for the most part. It has removed those gaps but it doesn't exactly sit on the y axis and the ends of the rounded stroke get cut off, it's progress for sure but unsure what other options there are ;(
Screenshot 2023-11-22 at 08 59 45

@ibrahimatcha
Copy link
Author

That's with negative values of -1.33 to try and get it as tight to the y axis as possible without cutting it off

@trashgod
Copy link
Contributor

As far as I know, the axis margin is the only relevant, supported property, also cited here for reference.

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