question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to create an "empty" chart

See original GitHub issue

Hi. I’m trying to fix a situation where I have no data to display in chart. In @chartjs I can do that. The chart is printed like so: image

Either when I try to create the chart without any series or when I add a series with zero-length arrays (for X and Y axis), I get an Exception.

With a series with empty values:

Exception in thread "main" java.lang.IllegalArgumentException: Y-Axis data cannot be empty!!!
	at org.knowm.xchart.CategoryChart.sanityCheck(CategoryChart.java:280)
	at org.knowm.xchart.CategoryChart.addSeries(CategoryChart.java:167)
	at org.knowm.xchart.CategoryChart.addSeries(CategoryChart.java:148)
	at LineChart04.getChart(LineChart04.java:40)
	at LineChart04.main(LineChart04.java:18)

With no series at all:

Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException
	at java.base/java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:721)
	at java.base/java.util.LinkedHashMap$LinkedValueIterator.next(LinkedHashMap.java:746)
	at org.knowm.xchart.internal.chartpart.Axis.getAxisTickCalculator(Axis.java:480)
	at org.knowm.xchart.internal.chartpart.Axis.getXAxisHeightHint(Axis.java:289)
	at org.knowm.xchart.internal.chartpart.Axis.preparePaint(Axis.java:153)
	at org.knowm.xchart.internal.chartpart.AxisPair.paint(AxisPair.java:124)
	at org.knowm.xchart.CategoryChart.paint(CategoryChart.java:308)
	at org.knowm.xchart.XChartPanel.paintComponent(XChartPanel.java:132)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1074)
	at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
	at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1083)
	at java.desktop/javax.swing.JLayeredPane.paint(JLayeredPane.java:590)
	at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:907)
	at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5262)
	at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedImpl(RepaintManager.java:1643)
	at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1618)
	at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1556)
	at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1323)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1060)
	at java.desktop/java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
	at java.desktop/sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78)
	at java.desktop/sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115)
	at java.desktop/java.awt.Container.paint(Container.java:2002)
	at java.desktop/java.awt.Window.paint(Window.java:3940)
	at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:876)
	at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:848)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:848)
	at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:823)
	at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:772)
	at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1890)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

I’m using the version 3.6.6.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timmoltercommented, Dec 25, 2020

You can use the following on a series:

series.setEnabled(false);

as a workaround. I never thought there’d be a usecase where someone would need to display an empty chart. I could perhaps add it if it’s justified.

0reactions
tbernecommented, Dec 28, 2020

@timmolter, It worked as expected! Thanks for your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Put an Empty Line Graph in Word - Azcentral
Step 1. Start Word. · Step 2. Browse to the empty line graph image file's location on your network. · Step 3. Double-click...
Read more >
How to Put an Empty Line Graph in Word
1. Click "Insert" in the Word ribbon. · 2. Click "Chart" in the Illustrations tab to open the Insert Chart dialog box. ·...
Read more >
How to create an empty charts and graphs in js - Syncfusion
You should create js file like emptyChart. · Create new chart instance by using new ej. · Assign the data using dataSource property...
Read more >
Display empty cells, null (#N/A) values, and hidden worksheet ...
Go to Chart Tools on the Ribbon, then on the Design tab, in the Data group, click Select Data. ... Click Hidden and...
Read more >
How do I create a blank chart? - Google Groups
some dummy data and create the chart, then remove the dummy data. -- Thanks, Shane Devenshire.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found