Beispiel #1
0
 def saveChartToDisk(self, basedir):
     """ Writes the chart to disk as a .png file in the specified
     directory. """
     fileName = basedir + os.sep
     txName = self.transactionName
     # fix for Jim Pringle's bug where illegal chars in transaction name
     # need a swap variable because replace() works inline
     fileName += txName.replace(" ", "_").replace("/", "_").replace(":", "_")
     fileName += self.getFilenameSuffix()
     logger.warn("creating " + fileName)
     chartFile = javaFile(fileName)  # translate string to java.io.File
     self.setChartOptions()
     logger.debug("DEBUG: height" + str(self.chart_height))
     logger.debug("DEBUG: weight" + str(self.chart_width))
     ChartUtilities.saveChartAsPNG(chartFile, self.chart, self.chart_width, self.chart_height)
Beispiel #2
0
 def save(self, parent, format):
     chooser = JFileChooser()
     #filter = FileNameExtensionFilter(
     #    format + " files",
     #    array([format, format.lower()], String))
     #chooser.setFileFilter(filter);
     returnVal = chooser.showSaveDialog(parent)
     if returnVal == JFileChooser.APPROVE_OPTION:
         fileName = chooser.getSelectedFile().getPath()
         if not fileName.upper().endswith('.' + format):
             fileName += '.' + format.lower()
         file = File(fileName)
     else:
         return
     if format == 'PNG':
         ChartUtilities.saveChartAsPNG(file, self.chart, self.exportX,
                                       self.exportY)
     elif format == 'SVG':
         domImpl = GenericDOMImplementation.getDOMImplementation()
         doc = domImpl.createDocument(None, "svg", None)
         svgGen = SVGGraphics2D(doc)
         svgGen.getGeneratorContext().setPrecision(6)
         self.chart.draw(
             svgGen, Rectangle2D.Double(0, 0, self.exportX, self.exportY),
             None)
         out = OutputStreamWriter(FileOutputStream(file), "UTF-8")
         svgGen.stream(out, True)  #True is for useCSS
         out.close()
     elif format == 'PDF':
         mapper = DefaultFontMapper()
         pageSize = Rectangle(self.exportX, self.exportY)
         doc = TextDocument(pageSize, 50, 50, 50, 50)
         out = BufferedOutputStream(FileOutputStream(file))
         writer = PdfWriter.getInstance(doc, out)
         doc.open()
         cb = writer.getDirectContent()
         tp = cb.createTemplate(self.exportX, self.exportY)
         g2 = tp.createGraphics(self.exportX, self.exportY, mapper)
         r2D = Rectangle2D.Double(0, 0, self.exportX, self.exportY)
         self.chart.draw(g2, r2D)
         g2.dispose()
         cb.addTemplate(tp, 0, 0)
         doc.close()
Beispiel #3
0
 def save(self, parent, format):
     chooser = JFileChooser()
     #filter = FileNameExtensionFilter(
     #    format + " files",
     #    array([format, format.lower()], String))
     #chooser.setFileFilter(filter);
     returnVal = chooser.showSaveDialog(parent)
     if returnVal == JFileChooser.APPROVE_OPTION:
         fileName = chooser.getSelectedFile().getPath()
         if not fileName.upper().endswith('.' + format):
             fileName += '.' + format.lower()
         file = File(fileName)
     else:
         return
     if format == 'PNG':
         ChartUtilities.saveChartAsPNG(file, self.chart, self.exportX, self.exportY)
     elif format == 'SVG':
         domImpl = GenericDOMImplementation.getDOMImplementation()
         doc = domImpl.createDocument(None, "svg", None)
         svgGen = SVGGraphics2D(doc)
         svgGen.getGeneratorContext().setPrecision(6)
         self.chart.draw(svgGen,
            Rectangle2D.Double(0, 0, self.exportX, self.exportY), None)
         out = OutputStreamWriter(FileOutputStream(file), "UTF-8")
         svgGen.stream(out, True) #True is for useCSS
         out.close()
     elif format == 'PDF':
         mapper = DefaultFontMapper()
         pageSize = Rectangle(self.exportX, self.exportY)
         doc = TextDocument(pageSize, 50, 50, 50, 50)
         out = BufferedOutputStream(FileOutputStream(file))
         writer = PdfWriter.getInstance(doc, out)
         doc.open()
         cb = writer.getDirectContent()
         tp = cb.createTemplate(self.exportX, self.exportY)
         g2 = tp.createGraphics(self.exportX, self.exportY, mapper)
         r2D = Rectangle2D.Double(0, 0, self.exportX, self.exportY)
         self.chart.draw(g2, r2D)
         g2.dispose()
         cb.addTemplate(tp, 0, 0)
         doc.close()
Beispiel #4
0
 def savepng(self, filename, size=(500, 500)):
     ChartUtilities.saveChartAsPNG(util.toFile(filename), self.chart, *size)
Beispiel #5
0
 def savepng(self, filename, size=(500,500)):
   ChartUtilities.saveChartAsPNG(util.toFile(filename), self.chart, *size)
dataset.addSeries( "Node count", values, bins)

chart = ChartFactory.createHistogram(
	"Node Count Histogram",
	"Bins",
	"Node count",
	dataset,
	PlotOrientation.VERTICAL,
	True,  # showLegend
	True,  # toolTips
	True,) # urls

# Save it as a PNG:
ChartUtilities.saveChartAsPNG(
  File("/Users/berthola/Desktop/Histotest/foo.png"),
  chart,
  800,
  600)

from org.jfree.chart import ChartPanel
from javax.swing import JFrame

class SimpleChart(JFrame):
	def __init__(self,chart):
		chartPanel = ChartPanel(chart)
		chartPanel.setPreferredSize(Dimension(800,600))
		chartPanel.setMouseZoomable(True,False)
		self.setContentPane(chartPanel)

s = SimpleChart(chart)
s.pack()
dataset.addSeries( "Random Stuff", values, bins)

chart = ChartFactory.createHistogram(
	"Example JFreeChart histogram",
	"This is the x axis",
	"This is the y axis",
	dataset,
	PlotOrientation.VERTICAL,
	True,  # showLegend
	True,  # toolTips
	True,) # urls

# Save it as a PNG:
ChartUtilities.saveChartAsPNG(
  File("/tmp/foo.png"),
  chart,
  800,
  600)

from org.jfree.chart import ChartPanel
from javax.swing import JFrame

class SimpleChart(JFrame):
	def __init__(self,chart):
		chartPanel = ChartPanel(chart)
		chartPanel.setPreferredSize(Dimension(800,600))
		chartPanel.setMouseZoomable(True,False)
		self.setContentPane(chartPanel)

s = SimpleChart(chart)
s.pack()