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

NPE on tooltips with BitmapEncoder.saveBitmap #862

Open
jc7447 opened this issue Jun 18, 2024 · 0 comments
Open

NPE on tooltips with BitmapEncoder.saveBitmap #862

jc7447 opened this issue Jun 18, 2024 · 0 comments

Comments

@jc7447
Copy link

jc7447 commented Jun 18, 2024

When upgrading from 3.6.6 to 3.8.8 , BitmapEncoder.saveBitmap throws NPE when tooltips are used.

Caused by: java.lang.NullPointerException: null
        at org.knowm.xchart.internal.chartpart.PlotContent_XY.doPaint(PlotContent_XY.java:304) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.internal.chartpart.PlotContent_.paint(PlotContent_.java:61) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.internal.chartpart.Plot_.paint(Plot_.java:37) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.internal.chartpart.Plot_AxesChart.paint(Plot_AxesChart.java:34) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.XYChart.paint(XYChart.java:417) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.BitmapEncoder.getBufferedImage(BitmapEncoder.java:277) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.BitmapEncoder.saveBitmap(BitmapEncoder.java:81) ~[xchart-3.8.8.jar:na]
        at org.knowm.xchart.BitmapEncoder.saveBitmap(BitmapEncoder.java:65) ~[xchart-3.8.8.jar:na]
public class LineChart01 {

	private static final String CHART_PREFIX = "chart-";

	private static final String PNG_SUFFIX = ".png";

	private static final String CHARTS = "charts-";

	public void getChart() throws IOException {

		// generates Log data
		List<Integer> xData = new ArrayList<Integer>();
		List<Double> yData = new ArrayList<Double>();
		for (int i = -3; i <= 3; i++) {
			xData.add(i);
			yData.add(Math.pow(10, i));
		}

		// Create Chart
		XYChart chart = new XYChartBuilder().width(800).height(600).title("Powers of Ten").xAxisTitle("Power").yAxisTitle("Value").build();

		// Customize Chart
		chart.getStyler().setChartTitleVisible(true);
		chart.getStyler().setLegendPosition(LegendPosition.InsideNW);
		chart.getStyler().setYAxisLogarithmic(true);
		chart.getStyler().setXAxisLabelRotation(45);

		chart.getStyler().setToolTipsEnabled(true);
		chart.getStyler().setToolTipsAlwaysVisible(true);
		chart.getStyler().setToolTipType(Styler.ToolTipType.yLabels);
		chart.getStyler().setToolTipBorderColor(Color.RED);

		// Series
		chart.addSeries("10^x", xData, yData);

		Path tempFolder = Files.createTempDirectory(CHARTS);

		Path chartFile = Files.createTempFile(tempFolder, CHART_PREFIX, PNG_SUFFIX);

		System.out.println(chartFile);

		BitmapEncoder.saveBitmap(chart, chartFile.toString(), BitmapEncoder.BitmapFormat.PNG);
	}
}

This was working fine in 3.6.6 :

chart-13192250370041411106

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

1 participant