Question

Does anyone know how to display an incanter chart to jpanel without reverting to jfreechart?

Was it helpful?

Solution

An Incanter chart is a JFreeChart under the hood so it's impossible to avoid the JFreeChart library altogether.

However, if you just want to include an incanter chart inside a Panel that you can use in a normal Swing application then there is a ready-made class called org.jfree.chart.ChartPanel which can do this for you.

Example code:

(ns my.chart
  (:import [org.jfree.chart ChartPanel])
  (:import [java.awt Component Dimension])
  (:import [javax.swing JFrame])
  (:use [incanter core stats charts]))

(defn show-component [^Component c]
  "Utility Function to display any Java component in a frame"
  (let [^JFrame frame (JFrame. "Test Window")]
    (doto frame
      (.add c)
      (.setSize (Dimension.  640 480)) 
      (.setVisible true))))

(show-component (ChartPanel. (function-plot sin -10 10)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top