Chart Library for NetBeans Platform Applications?

I had a pretty great time at Devoxx this year. Met lots of people (Joe Darcy from Project Coin stopping by at the Oracle booth to have a look at my demos of Project Coin features in NetBeans IDE was one of the highlights). As always, Devoxx is a great way to catch up with loads of people at the same time and exchange technical bits of information about projects you're working on.

One of the people I had a long chat with was Jaroslav Bachorik from the VisualVM team. Aside from other topics, I asked him how the charts work in VisualVM because I had heard that VisualVM includes an API for making charts, such as these in VisualVM itself:

However, if you're creating a plugin for VisualVM, wouldn't it be cool to use charts yourself? So Jaroslav and I (mainly Jaroslav) came up with the following "hello world" chart code:

SimpleXYChartDescriptor sxycd = SimpleXYChartDescriptor.decimal(0, true, 500);
sxycd.addLineItems("Test1","Test2","Test3");
SimpleXYChartSupport factory = ChartFactory.createSimpleXYChart(sxycd);
factory.addValues(System.currentTimeMillis(), new long[]{100,200,300});
factory.addValues(System.currentTimeMillis(), new long[]{100,200,300});
factory.addValues(System.currentTimeMillis(), new long[]{100,200,300});
factory.addValues(System.currentTimeMillis(), new long[]{100,200,300});
add(factory.getChart(), BorderLayout.CENTER);

The above comes from the "com.sun.tools.visualvm.charts" package, read about ChartFactory and SimpleXYChartDescriptor and SimpleXYChartSupport in the VisualVM Javadoc.

If you put the code above into a panel in a VisualVM plugin, you'll end up with this in VisualVM:

Note: Jaroslav updated my earlier VisualVM templates, which you can get here on the Plugin Portal, use them to create new panels and actions and other typical artifacts in a VisualVM plugin.

Finally, since we're able to create charts in VisualVM, shouldn't we also be able to use the chart API in any NetBeans Platform application? Sure, glad you asked. Include the VisualVM clusters ("visualvm" and "profiler" clusters from the "lib" folder in the JDK) in your NetBeans Platform application, then include the code above in a TopComponent, and here you are:

Nice. Not sure what all the features are of this chart library (read the VisualVM Javadoc for clues) and I'm pretty sure this chart library isn't competition for JFreeChart. But, still, if you like the charts in VisualVM and you want to do something similar, now you can.

 

Comments:

That's a nice tip. I was recently wondering if it would be possible to integrate some monitoring features of VisualVM into our own NB RCP based monitoring tool. This would avoid to launch it separately. Now I know it can be possible through the reuse of its cluster. Cool! I'all have to experiment.

Posted by Jean-Marc Borer on November 18, 2010 at 05:52 PM PST #

Hi Jean-Marc. Yes, good point, and there's more good news in connection with this that you'll find useful, I'll blog about it soon. Basically, it's possible to include the NetBeans Profiler in your own application (either to monitor the application under development, from inside the application itself, or for the case where the end users of your application need the monitoring capabilities of NetBeans IDE themselves). I'll blog about this scenario soon, someone at Devoxx told me about this, it's actually a scenario that's being used in real life at a company in Germany.

Posted by Geertjan Wielenga on November 18, 2010 at 06:00 PM PST #

Hi Geertjan. I'm sorry to bother with a non related comment, but I found in you blog a 2008 post with the subject "Feature on Demand". I'm researching best pratices on modularization as modular strategies for a huge ERP, but I can't find anything else about that "Feature on Demand". Can you please help with some material or tips or a simple guidence, because until January 31, I have to put on my boss desk, a nice formula to prove the power of Netbeans Platform.

Thanks for your contribution on this blog, it became required reading for my day to day.

Regards.

Posted by Thiago Bonfante on November 18, 2010 at 07:38 PM PST #

Here's your answer, Thiago:

http://wiki.netbeans.org/FitnessForever#Solution

Please contact me directly at geertjan dot wielenga at oracle dot com and I'll help you directly in setting up the nice formula for your boss!

Posted by Geertjan on November 19, 2010 at 04:44 AM PST #

It seems it is even possible to use this outside the NetBeans platform - by sticking Geertjan's example above into a JDialog and just including the jars: org-netbeans-lib-profiler-charts.jar, com-sun-tools-visualvm-charts.jar, com-sun-tools-visualvm-uisupport.jar and org-netbeans-lib-profiler-ui.jar . Pretty cool!

Posted by Ernest on November 19, 2010 at 06:31 PM PST #

would love to play with it (outside of NetBeans, being a Eclipse fangirl :-), but seems like something missing (after copying the all jars from the jdk lib/visualvm/visualvm/Modules and from lib/visualVM/profiler3/Modules). Running the example from the devoxx blog entry throws:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openide/util/NbBundle
at com.sun.tools.visualvm.charts.xy.SimpleXYChartUtils.createDetailsString(SimpleXYChartUtils.java:463)
at com.sun.tools.visualvm.charts.xy.SimpleXYChartUtils.createDetailsArea(SimpleXYChartUtils.java:305)

Whatelse do I need?

Thanks
Jeanette

Posted by Kleopatra on November 21, 2010 at 10:45 PM PST #

org-openide-util.jar, which you'll find in the "platform" folder in VisualVM.

Posted by Geertjan Wielenga on November 22, 2010 at 03:23 AM PST #

Very interesting. When using it outside of NetBeans (e.g. WebApplication on JEE), is it possible to export the chart to graphics file, e.g. PNG or JPEG?

Posted by Owl on November 22, 2010 at 03:09 PM PST #

Hi Owl, these charts don't support export to bitmaps. As described in the article, VisualVM charts are designed for displaying live data (in Java applications). JFreeChart will do better job for you when creating charts on server-side.

Posted by Jiri Sedlacek on November 23, 2010 at 12:38 AM PST #

Hi there,

Well first of all great job!!

What I want to do is to extend the API for the VisualVM charts. I would like the to add things like the jfreechart has. Example plot points, or linepoints and not only lines, define the colour of the line, add Graphics inside the plot as Rectangle2D and etc.
So my question is how I can start doing that?
I am trying to find the source code but I cant.

Thanks,

Pol

Posted by Pol on December 28, 2010 at 02:13 AM PST #

Hey, after I included the visualvm.charts package, how come it keeps complaining it can't find the "add" function from your code. How do I fix that? Thank you

Posted by Clint on January 17, 2012 at 11:06 PM PST #

Great information. Realtime plotting libraries seem to be a constant point of discussion for various platforms. I would love to hear if you have any updates for attractive realtime plotting in java.

I was excited to use the fast plotting of visualvm in my netbeans platform project but after including the two clusters you identified in your post I still received an unresolved symbol error in the project for your example code. After considerable searching I attempted to import com.sun.tools.visualvm.* but to no avail. I'm a bit of a noob with netbeans, the netbeans platform, and clusters so it might be something simple. But after an hour of searching I've hit a bit of a road block and was hoping that I'm missing something obvious.

Posted by Kyle on December 24, 2012 at 07:10 PM PST #

Kyle, not sure what I can do based on the info you've provided. What does "an unresolved symbol error" mean -- isn't that too generic for you to hope for me to be able to help you?

Posted by Geertjan on December 25, 2012 at 02:20 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today