67179

JFreeChart Dial chart in Coldfusion

Question:

Has anyone an example of implementing a JFreechart Dial chart on Coldfusion?

Thanks

Answer1:

<em>(This probably should not be a separate answer, but the other was already pretty long. So I am posting it separately to keep things organized and easy to find.)</em>

In case you are looking for what jFreeChart calls a MeterChart, here is a quick and dirty example of that chart type.

<img alt="JFreeChart MeterChart" class="b-lazy" data-src="https://i.stack.imgur.com/X0sK9.png" data-original="https://i.stack.imgur.com/X0sK9.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

<strong>MeterChart Code:</strong>

<cfscript> // my chart settings chartTitle = "My Meter Chart"; arrowValue = 55; arrowUnits = "widgets"; chartWidth = 500; chartHeight = 500; // initialize meter ranges (LOW, MEDIUM, HIGH) // note: quick and ugly code in dire need of improvement ... low = createSolidMeterInterval("Low", 0, 40, createAwtColor(0, 255, 0, 120)); med = createSolidMeterInterval("Med", 40, 60, createAwtColor(255, 255, 0, 120)); high = createSolidMeterInterval("High", 60, 100, createAwtColor(255, 0, 0, 120)); // initialize arrow value DefaultValueDataset = createObject("java", "org.jfree.data.general.DefaultValueDataset"); meterPointer = DefaultValueDataset.init(arrowValue); //initialize plot and apply settings plot = createObject("java", "org.jfree.chart.plot.MeterPlot").init(); plot.setDataset(meterPointer); plot.setTickLabelsVisible(true); plot.addInterval(low); plot.addInterval(med); plot.addInterval(high); plot.setUnits(arrowUnits); // create chart and convert it to an image chart = createObject("java", "org.jfree.chart.JFreeChart").init(chartTitle, plot); ChartUtilities = createObject("java", "org.jfree.chart.ChartUtilities"); ChartUtilities.applyCurrentTheme(chart); // applyCurrentTheme seems to overwrite some settings, so we must reapply them Color = createObject("java", "java.awt.Color"); plot.setBackgroundPaint(Color.GRAY); plot.setNeedlePaint(Color.BLACK); chartImage = chart.createBufferedImage(chartWidth, chartHeight); ImageFormat = createObject("java", "org.jfree.chart.encoders.ImageFormat"); EncoderUtil = createObject("java", "org.jfree.chart.encoders.EncoderUtil"); bytes = EncoderUtil.encode( chartImage, ImageFormat.PNG); </cfscript> <!--- display in browser ---> <cfcontent type="image/png" variable="#bytes#">

<strong>Auxiliary functions:</strong>

<cfscript> // quick and ugly functions. could be improved ... function createSolidMeterInterval(Title, fromValue, toValue, BgColor) { var Range = createObject("java", "org.jfree.data.Range").init(arguments.fromValue, arguments.toValue); var MeterInterval = createObject("java", "org.jfree.chart.plot.MeterInterval"); return MeterInterval.init(arguments.Title, Range // interval from / to range , javacast("null", "") // outline color , javacast("null", "") // outline stroke , arguments.BgColor // background color ); } // using java.awt.Color is a pain due to all the javacasts ... function createAwtColor(r, g, b, alpha) { var color = createObject("java", "java.awt.Color"); return color.init( javacast("int", arguments.r) , javacast("int", arguments.g) , javacast("int", arguments.b) , javacast("int", arguments.alpha) // transparency ); } </cfscript>

Answer2:

The package <a href="http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/demo/package-summary.html" rel="nofollow">org.jfree.chart.demo</a> has examples of how to construct a few basic charts; click on the class name to see the source. The methods of <a href="http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/ChartFactory.html" rel="nofollow">org.jfree.chart.ChartFactory</a> show how to construct still more. The class <a href="http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/ChartUtilities.html" rel="nofollow">org.jfree.chart.ChartUtilities</a> includes methods to stream charts in several formats. A corresponding response.setContentType() works from any servlet container.

If this is <em>terra incognita</em>, I'd recommend <a href="http://www.jfree.org/jfreechart/devguide.html" rel="nofollow"><em>The JFreeChart Developer Guide</em></a><sup>†</sup>.

<sup>†</sup><sub><em>Disclaimer: Not affiliated with Object Refinery Limited; just a satisfied customer and very minor contributor.</em></sub>

Answer3:

Using trashgod's suggestions, I created a very rudimentary example for CF7. You can obviously do <em>much</em> more with it. Just review the api and/or purchase the developer guide.

<img alt="Sample Dial Chart" class="b-lazy" data-src="https://i.stack.imgur.com/OUSHq.png" data-original="https://i.stack.imgur.com/OUSHq.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

<strong>Install:</strong> Download latest jfreeChart. Copy the following jars into {cf_root}\WEB-INF\lib and restart CF. <em>Note, jar version numbers may vary.</em>

<ul><li>jfreechart-1.0.13.jar</li> <li>jcommon-1.0.16.jar</li> </ul>

<strong>Sample:</strong>

<cfscript> // my chart settings chartTitle = "My Dial Chart"; arrowValue = 55; dialMinimum = 0; dialMaximum = 100; chartWidth = 500; chartHeight = 500; // initialize basic components of the chart // see jFreeChart API on how to customize the components settings further DefaultValueDataset = createObject("java", "org.jfree.data.general.DefaultValueDataset"); pointerValue = DefaultValueDataset.init(arrowValue); dialPointer = createObject("java", "org.jfree.chart.plot.dial.DialPointer$Pointer").init(); dialFrame = createObject("java", "org.jfree.chart.plot.dial.StandardDialFrame").init(); dialBackground = createObject("java", "org.jfree.chart.plot.dial.DialBackground").init(); // tweak the default range to make it more appealing. // see angle/extent: http://java.sun.com/developer/technicalArticles/GUI/java2d/java2dpart1.html dialScale = createObject("java", "org.jfree.chart.plot.dial.StandardDialScale").init(); dialScale.setLowerBound(dialMinimum); dialScale.setUpperBound(dialMaximum); dialScale.setStartAngle(-150); dialScale.setExtent(-240); //initialize plot and apply settings plot = createObject("java", "org.jfree.chart.plot.dial.DialPlot").init(); plot.setDialFrame(dialFrame); plot.setBackground(dialBackground); plot.setDataset(pointerValue); plot.addScale(0, dialScale); plot.addPointer(dialPointer); // create chart and convert it to an image chart = createObject("java", "org.jfree.chart.JFreeChart").init(chartTitle, plot); chartImage = chart.createBufferedImage(chartWidth, chartHeight); ImageFormat = createObject("java", "org.jfree.chart.encoders.ImageFormat"); EncoderUtil = createObject("java", "org.jfree.chart.encoders.EncoderUtil"); bytes = EncoderUtil.encode( chartImage, ImageFormat.PNG); </cfscript> <!--- display in browser ---> <cfcontent type="image/png" variable="#bytes#">

Recommend

  • Open new frame or chart when a bar or a bar chart is clicked
  • How can Implenent a Pie Chart using jFreechart in jsp? [duplicate]
  • how does zoomRange() works?
  • JFreeChart - IntervalMarker vertical?
  • How to to refresh the chart in ChartPanel class after loading the file?
  • jfreechart setbackgroundpaint not doing anything
  • How can JFreeChart print a scatter point directly on the x axis?
  • JFreechart color square grid on XY plot
  • Jfree chart change Y axis data
  • How to perform GridSearchCV with cross validation in python
  • JFreeChart Dial chart in Coldfusion
  • Best java 3D pie chart API [closed]
  • How to get selected elements of panels in JList (overlay selected elements)
  • Use JFuzzyLogic and android app
  • Free library supporting Gantt charts and granularity
  • Identifying closest value in a column for each filter using Pandas
  • Enabling/Disabling drawing of a JFreeChart
  • Unicode — What's going on here?
  • Java Visualisation / Charting library like Google Charts / Visualisation
  • Wait for Swing to finish updating JProgressBar before continuing
  • Exception in thread “AWT-EventQueue-0” java.lang.NoClassDefFoundError
  • JFreeChart BarChart - Category Markers
  • How to trigger a KeyPressed event for unit testing in JAVA
  • java drawing on JPanel with timer/delay
  • C# “cannot assign field because it is a foreach iteration variable”
  • JFreechart X and Y axis scaling
  • Stacked Bar Chart with percentage composition inside the Bar and total above the Bar in JFreeChart
  • Exception in the iconization of JInternalFrame with DefaultDesktopManager
  • Problem in concatenation of objects in javascript
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • How to use carriage return with multiple line?
  • Algorithm for a smudge tool?
  • How reduce the height of an mschart by breaking up the y-axis
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • How do I rollback to a specific git commit
  • Android Google Maps API OnLocationChanged only called once