Search Results

Search found 11 results on 1 pages for 'chartpanel'.

Page 1/1 | 1 

  • Get rid of jfreechart chartpanel unnecessary space

    - by ryvantage
    I am trying to get a JFreeChart ChartPanel to remove unwanted extra space between the edge of the panel and the graph itself. To best illustrate, here's a SSCCE (with JFreeChart installed): public static void main(String[] args) { JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 1; gbc.weighty = 1; gbc.gridy = 1; gbc.gridx = 1; panel.add(createChart("Sales", Chart_Type.DOLLARS, 100000, 115000), gbc); gbc.gridx = 2; panel.add(createChart("Quotes", Chart_Type.DOLLARS, 250000, 240000), gbc); gbc.gridx = 3; panel.add(createChart("Profits", Chart_Type.PERCENTAGE, 40.00, 38.00), gbc); JFrame frame = new JFrame(); frame.add(panel); frame.setSize(800, 300); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private static ChartPanel createChart(String title, Chart_Type type, double goal, double actual) { double maxValue = goal * 2; double yellowToGreenNum = goal; double redToYellowNum = goal * .75; DefaultValueDataset dataset = new DefaultValueDataset(actual); JFreeChart jfreechart = createChart(dataset, Math.max(actual, maxValue), redToYellowNum, yellowToGreenNum, title, type); ChartPanel chartPanel = new ChartPanel(jfreechart); chartPanel.setBorder(new LineBorder(Color.red)); return chartPanel; } private static JFreeChart createChart(ValueDataset valuedataset, Number maxValue, Number redToYellowNum, Number yellowToGreenNum, String title, Chart_Type type) { MeterPlot meterplot = new MeterPlot(valuedataset); meterplot.setRange(new Range(0.0D, maxValue.doubleValue())); meterplot.addInterval(new MeterInterval(" Goal Not Met ", new Range(0.0D, redToYellowNum.doubleValue()), Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128))); meterplot.addInterval(new MeterInterval(" Goal Almost Met ", new Range(redToYellowNum.doubleValue(), yellowToGreenNum.doubleValue()), Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64))); meterplot.addInterval(new MeterInterval(" Goal Met ", new Range(yellowToGreenNum.doubleValue(), maxValue.doubleValue()), Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64))); meterplot.setNeedlePaint(Color.darkGray); meterplot.setDialBackgroundPaint(Color.white); meterplot.setDialOutlinePaint(Color.gray); meterplot.setDialShape(DialShape.CHORD); meterplot.setMeterAngle(260); meterplot.setTickLabelsVisible(false); meterplot.setTickSize(maxValue.doubleValue() / 20); meterplot.setTickPaint(Color.lightGray); meterplot.setValuePaint(Color.black); meterplot.setValueFont(new Font("Dialog", Font.BOLD, 0)); meterplot.setUnits(""); if(type == Chart_Type.DOLLARS) meterplot.setTickLabelFormat(NumberFormat.getCurrencyInstance()); else if(type == Chart_Type.PERCENTAGE) meterplot.setTickLabelFormat(NumberFormat.getPercentInstance()); JFreeChart jfreechart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, meterplot, false); return jfreechart; } enum Chart_Type { DOLLARS, PERCENTAGE } If you resize the frame, you can see that you cannot make the edge of the graph go to the edge of the panel (the panels are outlined in red). Especially on the bottom - there is always a gap between the bottom the graph and the bottom of the panel. Is there a way to make the graph fill the entire area? Is there a way to at least guarantee that it is touching one edge of the panel (i.e., it is touching the top and bottom or the left and right) ??

    Read the article

  • Place JComponent On The Top Of JXLayer

    - by Yan Cheng CHEOK
    Hello, currently, I had successful applying JXLayer on my charting component, to draw a yellow information box on the top of it. final org.jdesktop.jxlayer.JXLayer<ChartPanel> layer = new org.jdesktop.jxlayer.JXLayer<ChartPanel>(this.chartPanel); this.chartLayerUI = new ChartLayerUI<ChartPanel>(this); layer.setUI(this.chartLayerUI); At the same time, I wish to add the following JComponent (DefaultDrawingView) on the top of JXLayer. This JComponent has the ability 1) To receive mouse event to draw figures on itself. Within ChartLayerUI, I add the following code @Override @SuppressWarnings("unchecked") public void installUI(JComponent c) { super.installUI(c); JXLayer<JComponent> l = (JXLayer<JComponent>) c; l.getGlassPane().setLayout(new java.awt.BorderLayout()); // this.view is DefaultDrawingView drawing object. l.getGlassPane().add(this.view, java.awt.BorderLayout.CENTER); } However, after having the above code, I get the following outcome 1) My charting component ChartPanel are being blocked by DefaultDrawingView 2) My charting component no longer able to receive mouse event. What I wish is that A) ChartPanel and DefaultDrawingView able to show up B) ChartPanel and DefaultDrawingView able to receive mouse event Is there other steps I had missed out, or did wrong? Thanks.

    Read the article

  • JFreeChart CategoryPlot overwrites categories

    - by Christine
    Hi, I am new to using JFreeChart and I'm sure there is a simple solution to my problem . . PROBLEM: I have a chart that shows multiple "events types" along the date X axis. The Y axis shows the "event category". My problem is that only the latest date of an event type is shown for each category. In the example below The chart shows data points for Event Type 1 at June 20th(Category 1) and at June 10th (Category 2). I had also added a data point for June 10th, Category 1 but the June 20th point erases it. I think I am misunderstanding how the CategoryPlot is working. Am I using the wrong type of chart? I thought a scatter chart would be the ticket but it only accepts numerical values. I need to have discrete string categories on my Y-axis. If anyone can point me in the right direction, you would really make my day. Thanks for reading! -Christine (The code below works as-is. It is as simple as I could make it) import java.awt.Dimension; import javax.swing.JPanel; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.renderer.category.LineAndShapeRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.time.Day; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; public class EventFrequencyDemo1 extends ApplicationFrame { public EventFrequencyDemo1(String s) { super(s); CategoryDataset categorydataset = createDataset(); JFreeChart jfreechart = createChart(categorydataset); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartpanel); } private static JFreeChart createChart(CategoryDataset categorydataset) { CategoryPlot categoryplot = new CategoryPlot(categorydataset, new CategoryAxis("Category"), new DateAxis("Date"), new LineAndShapeRenderer(false, true)); categoryplot.setOrientation(PlotOrientation.HORIZONTAL); categoryplot.setDomainGridlinesVisible(true); return new JFreeChart(categoryplot); } private static CategoryDataset createDataset() { DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); Day june10 = new Day(10, 6, 2002); Day june20 = new Day(20, 6, 2002); // This event is overwritten by June20th defaultcategorydataset.setValue(new Long(june10.getMiddleMillisecond()), "Event Type 1", "Category 1"); defaultcategorydataset.setValue(new Long(june10.getMiddleMillisecond()), "Event Type 1", "Category 2"); // Overwrites the previous June10th event defaultcategorydataset.setValue(new Long(june20.getMiddleMillisecond()), "Event Type 1", "Category 1"); defaultcategorydataset.setValue(new Long(june20.getMiddleMillisecond()), "Event Type 2", "Category 2"); return defaultcategorydataset; } public static JPanel createDemoPanel() { JFreeChart jfreechart = createChart(createDataset()); return new ChartPanel(jfreechart); } public static void main(String args[]) { EventFrequencyDemo1 eventfrequencydemo1 = new EventFrequencyDemo1("Event Frequency Demo"); eventfrequencydemo1.pack(); RefineryUtilities.centerFrameOnScreen(eventfrequencydemo1); eventfrequencydemo1.setVisible(true); } }

    Read the article

  • Combination of JFreeChart with JXLayer with JHotDraw

    - by Yan Cheng CHEOK
    Recently, I had use JXLayer, to overlay two moving yellow message boxes, on the top of JFreeChart http://yccheok.blogspot.com/2010/02/investment-flow-chart.html I was wondering, had anyone experience using JXLayer + JHotdraw, to overlay all sorts of figures (Re-sizable text box, straight line, circle...), on the top of JFreeChart. I just would like to add drawing capability, without changing the JFreeChart source code. So that, JStock's user may draw trending lines, annotation text on their favorite stock charting. The code skeleton is as follow : // this.chartPanel is JFreeChartPanel final org.jdesktop.jxlayer.JXLayer<ChartPanel> layer = new org.jdesktop.jxlayer.JXLayer<ChartPanel>(this.chartPanel); this.myUI = new MyUI<ChartPanel>(this); layer.setUI(this.myUI); public class MyUI<V extends javax.swing.JComponent> extends AbstractLayerUI<V> { @Override protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) { // Previous, I am using my own hand-coded, to draw the yellow box // // Now, How can I make use of JHotDraw at here, to draw various type of // figures? } @Override protected void processMouseEvent(MouseEvent e, JXLayer<? extends V> layer) { // How can I make use of JHotDraw at here? } @Override protected void processMouseMotionEvent(MouseEvent e, JXLayer<? extends V> layer) { // How can I make use of JHotDraw at here? } } As you see, I already got Graphics2D g2 from paintLayer method. How is it possible that I can pass the Graphics2D object to JHotDraw, and let JHotDraw handles all the drawing. My experience in using JHotDraw are with org.jhotdraw.draw.DefaultDrawingView org.jhotdraw.draw.DefaultDrawingEditor I am able to use them to draw various figures, by clicking on the toolbar and click on drawing area. How is it possible I can use DefaultDrawingView and DefaultDrawingEditor within MyUI's paintLayer? Also, shall I let MyUI handles the mouse event, or JHotDraw? Sorry, I start getting confused.

    Read the article

  • Save/Load jFreechart TimeSeriesCollection chart from XML

    - by IMAnis_tn
    I'm working with this exemple wich put rondom dynamic data into a TimeSeriesCollection chart. My problem is that i can't find how to : 1- Make a track of the old data (of the last hour) when they pass the left boundary (because the data point move from the right to the left ) of the view area just by implementing a horizontal scroll bar. 2- Is XML a good choice to save my data into when i want to have all the history of the data? public class DynamicDataDemo extends ApplicationFrame { /** The time series data. */ private TimeSeries series; /** The most recent value added. */ private double lastValue = 100.0; public DynamicDataDemo(final String title) { super(title); this.series = new TimeSeries("Random Data", Millisecond.class); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); } private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart( "Dynamic Data Demo", "Time", "Value", dataset, true, true, false ); final XYPlot plot = result.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(0.0, 200.0); return result; } public void go() { final double factor = 0.90 + 0.2 * Math.random(); this.lastValue = this.lastValue * factor; final Millisecond now = new Millisecond(); System.out.println("Now = " + now.toString()); this.series.add(new Millisecond(), this.lastValue); } public static void main(final String[] args) throws InterruptedException { final DynamicDataDemo demo = new DynamicDataDemo("Dynamic Data Demo"); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); while(true){ demo.go(); Thread.currentThread().sleep(1000); } } }

    Read the article

  • Flex: How to refresh/repaint a chart?

    - by Rob
    I have a chart for which the data is provided asynchronously via a CallResponder (used with a RemoteObject). However, it does not seem possible to update the chart with the data after it has been initially drawn. Here are the relevant snippets of (simplified) code: // code below is in the application MXML <mx:CallResponder id="result" result="resultHandler(event)" /> private function resultHandler(event:ResultEvent):void { // panel is an instance of ChartPanel this.panel.init(event.result); } // invoked when user clicks a button private function displayChart():void { this.currentState = "ShowChart"; result.token = remoteObject.getUrlStatistics(); } // code below is in ChartPanel <mx:BarChart id="chart" /> public function init(value:Object):void { var xml:XMLList = XMLList(value); var data:ArrayCollection = new ArrayCollection(); for each (var element:XML in xml.children()) { // not shown: extract value out of XML, put in ArrayList data.addItem(...); } this.chart.dataProvider = data; } The result is that it draws an empty chart. the resultHandler function or init function in ChartPanel needs to trigger a repaint or something similar. I have tried: Firing a collection modified event after assigning it to chart.dataProvider calling invalidateDisplayList (tried with all components) binding the chart data provider to a variable, and doing the above. changing the view state on the last line of resultHandler. None of them worked. When I fetch the data and cache it locally, then use it to call init synchronously, the chart displays correctly. What am I missing here?

    Read the article

  • Live Updates in PrimeFaces Line Chart

    - by Geertjan
    In the Facelets file: <p:layoutUnit position="center"> <h:form> <p:poll interval="3" update=":chartPanel" autoStart="true" /> </h:form> <p:panelGrid columns="1" id="chartPanel"> <p:lineChart xaxisLabel="Time" yaxisLabel="Position" value="#{chartController.linearModel}" legendPosition="nw" animate="true" style="height:400px;width: 1000px;"/> </p:panelGrid> </p:layoutUnit> The controler: import java.io.Serializable; import javax.inject.Named; import org.primefaces.model.chart.CartesianChartModel; import org.primefaces.model.chart.ChartSeries; @Named public class ChartController implements Serializable { private CartesianChartModel model; private ChartSeries data; public ChartController() { createLinearModel(); } private void createLinearModel() { model = new CartesianChartModel(); model.addSeries(getStockChartData("Stock Chart")); } private ChartSeries getStockChartData(String label) { data = new ChartSeries(); data.setLabel(label); for (int i = 1; i <= 20; i++) { data.getData().put(i, (int) (Math.random() * 1000)); } return data; } public CartesianChartModel getLinearModel() { return model; } } Based on this sample.

    Read the article

  • Real-time graphing in Java

    - by thodinc
    I have an application which updates a variable about between 5 to 50 times a second and I am looking for some way of drawing a continuous XY plot of this change in real-time. Though JFreeChart is not recommended for such a high update rate, many users still say that it works for them. I've tried using this demo and modified it to display a random variable, but it seems to use up 100% CPU usage all the time. Even if I ignore that, I do not want to be restricted to JFreeChart's ui class for constructing forms (though I'm not sure what its capabilities are exactly). Would it be possible to integrate it with Java's "forms" and drop-down menus? (as are available in VB) Otherwise, are there any alternatives I could look into? EDIT: I'm new to Swing, so I've put together a code just to test the functionality of JFreeChart with it (while avoiding the use of the ApplicationFrame class of JFree since I'm not sure how that will work with Swing's combo boxes and buttons). Right now, the graph is being updated immediately and CPU usage is high. Would it be possible to buffer the value with new Millisecond() and update it maybe twice a second? Also, can I add other components to the rest of the JFrame without disrupting JFreeChart? How would I do that? frame.getContentPane().add(new Button("Click")) seems to overwrite the graph. package graphtest; import java.util.Random; import javax.swing.JFrame; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.data.time.Millisecond; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; public class Main { static TimeSeries ts = new TimeSeries("data", Millisecond.class); public static void main(String[] args) throws InterruptedException { gen myGen = new gen(); new Thread(myGen).start(); TimeSeriesCollection dataset = new TimeSeriesCollection(ts); JFreeChart chart = ChartFactory.createTimeSeriesChart( "GraphTest", "Time", "Value", dataset, true, true, false ); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); JFrame frame = new JFrame("GraphTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ChartPanel label = new ChartPanel(chart); frame.getContentPane().add(label); //Suppose I add combo boxes and buttons here later frame.pack(); frame.setVisible(true); } static class gen implements Runnable { private Random randGen = new Random(); public void run() { while(true) { int num = randGen.nextInt(1000); System.out.println(num); ts.addOrUpdate(new Millisecond(), num); try { Thread.sleep(20); } catch (InterruptedException ex) { System.out.println(ex); } } } } }

    Read the article

  • Dynamic graphing using Jfreechart

    - by Albinoswordfish
    Right now I'm using JFreeChart in order to create a dynamic chart. However the chart is significantly slowing down my GUI. I was just wondering, is jfreechart generally heavy in the graphics department (my computer is not fast at all). Or is there a way to configure the ChartPanel to better optimize dynamic charting.

    Read the article

  • create xml from object

    - by Gannesh
    Basically i want to create XMLDesigner kind of thing in Flex, using which user can add/edit components and properties of view/dashboard. i am storing view structure in a xml file. i parsed that file at runtime and display view. How to convert an object (having properties and sub-objects) to xml node (having attributes and elements) and add that xml to the existing xml file. so that next time when i parsed xml file i'll get that new component in my view/dashboard. for e.g, object structure of component in xml file : <view id="productView" label="Products"> <panel id="chartPanel" type="CHART" ChartType="Pie2D" title="Productwise Sales" x="215" y="80" width="425" height="240" showValues="0" > </panel> </view> Thanks in Advance.

    Read the article

  • iphone image is leaking, but where?

    - by Brodie4598
    the image that is being displayed in this code is leaking but I cant figure out how. What I have a tableview that displays images to be displayed. Each time a user selects an image, it should remove the old image, download a new one, then add it to the scroll view. But the old image is not being released and I cant figure out why... -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [imageView removeFromSuperview]; self.imageView = nil; NSUInteger row = [indexPath row]; NSString *tempC = [[NSString alloc]initWithFormat:@"http://www.website.com/%@_0001.jpg",[pdfNamesFinalArray objectAtIndex:row] ]; chartFileName = tempC; pdfName = [pdfNamesFinalArray objectAtIndex:row]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsPath = [paths objectAtIndex:0]; NSString *tempString = [[[NSString alloc]initWithFormat:@"%@/%@.jpg",docsPath,pdfName]autorelease]; NSData *data = [NSData dataWithContentsOfFile:tempString]; if (data != NULL){ self.imageView = nil; [imageView removeFromSuperview]; self.imageView = nil; UIImageView *tempImage = [[[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]autorelease]; self.imageView = tempImage; [data release]; scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height); scrollView.maximumZoomScale = 1; scrollView.minimumZoomScale = .6; scrollView.clipsToBounds = YES; scrollView.delegate = self; [scrollView addSubview:imageView]; scrollView.zoomScale = .37; } else { [data release]; self.imageView = nil; [imageView removeFromSuperview]; self.imageView = nil; activityIndicator.hidden = NO; getChartsButton.enabled = NO; chartListButton.enabled = NO; saveChartButton.enabled = NO; [NSThread detachNewThreadSelector:@selector(downloadImages) toTarget:self withObject:nil]; } chartPanel.hidden = YES; } -(void) downloadImages { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; self.imageView = nil; [imageView removeFromSuperview]; NSURL *url = [[[NSURL alloc]initWithString:chartFileName]autorelease]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImageView *tempImage = [[[UIImageView alloc]initWithImage:[UIImage imageWithData:data]]autorelease]; self.imageView = tempImage; tempImage = nil; scrollView.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height); scrollView.maximumZoomScale = 1; scrollView.minimumZoomScale = .37; scrollView.clipsToBounds = YES; scrollView.delegate = self; [scrollView addSubview:imageView]; scrollView.zoomScale = .6; activityIndicator.hidden = YES; getChartsButton.enabled = YES; chartListButton.enabled = YES; saveChartButton.enabled = YES; [pool drain]; [pool release]; }

    Read the article

1