ERLEDIGT
NEIN
NEIN
ANTWORTEN
0
0
ZUGRIFFE
256
256
EMPFEHLEN
-
Hey,
Ich suche schon seit einigen tagen nach einer möglichkeit meinen Chart (jfreechart) via Button click updaten / refrechen zu lassen falls z.B neue daten in der datenbank ankommen oder falls der user mal ne andere hintergrundfarbe wählt.
Das ist mein servlet der den chart generiert :
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
import org.jfree.data.jdbc.JDBCPieDataset; import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartUtilities; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.IOException; import java.io.OutputStream; import java.sql.SQLException; import java.sql.DriverManager; import java.sql.Connection; public class PieChart extends HttpServlet { private static final long serialVersionUID = 1L; public void init() throws ServletException { super.init(); try { Class.forName("org.postgresql.Driver").newInstance(); } catch (InstantiationException e) { throw new ServletException(e); } catch (IllegalAccessException e) { throw new ServletException(e); } catch (ClassNotFoundException e) { throw new ServletException(e); } } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String colour = request.getParameter("colour"); Connection connection = null; try { connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jfreechartdb", "jfreechart", "password"); JDBCPieDataset dataset = new JDBCPieDataset(connection); dataset.executeQuery("Select * From piedata1"); JFreeChart chart = ChartFactory.createPieChart("Pie Chart", dataset, true, false, false); response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, 450, 400); } catch (SQLException e) { log("Exception retrieving chart data", e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { log("Could not close Connection", e); } } } } }
mein Portlet soweit :
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
import com.vaadin.Application; import com.vaadin.terminal.Sizeable; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.MenuBar.Command; import com.vaadin.ui.MenuBar.MenuItem; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.MenuBar; import com.vaadin.ui.Slider; import com.vaadin.ui.Window; import com.vaadin.ui.Button; public class vaadinportlet extends Application implements ClickListener { Button Refresh; //Refresh Button public Window window; //Main Window Label Kiviat; //Kiviat Chart Label Kuchen; //Pie Chart private MenuBar menubar = new MenuBar(); private static final long serialVersionUID = 1L; @SuppressWarnings("serial") public void init() { window = new Window(""); setMainWindow(window); HorizontalLayout fittingLayout = new HorizontalLayout(); Kiviat = new Label("<img src=http://localhost:8888/portlet/KiviatDiagramm", Label.CONTENT_XHTML); window.addComponent(Kiviat); Kuchen = new Label("<img src=http://localhost:8888/portlet/PieChart", Label.CONTENT_XHTML); window.addComponent(Kuchen); Kuchen.setVisible(false); fittingLayout.setWidth(Sizeable.SIZE_UNDEFINED, 0); Refresh = new Button("Refresh"); Refresh.addListener(this); fittingLayout.addComponent(Refresh); window.addComponent(fittingLayout); //Start menu "Config" final MenuBar.MenuItem config = menubar.addItem("Config", null); final MenuBar.MenuItem newItem = config.addItem("Select Chart Typ", null); config.addSeparator(); newItem.addItem("PieChart", new Command(){ public void menuSelected(MenuItem selectedItem) { Kuchen.setVisible(false); } }); fittingLayout.addComponent(menubar); //End Menu "Config" } public void buttonClick(ClickEvent e) { if(e.getSource() == Refresh){ Refresh.setCaption("Refresh on"); } } @SuppressWarnings("serial") private Command menuCommand = new Command() { public void menuSelected(MenuItem selectedItem) { } }; }
Beim klicken des "Refresh" Buttons soll der Chart neu gezeichnet werden .
Mfg
kiesa747
Ähnliche Themen
-
Arbeitsaufwand für Portlet (Liferay)?
Von Andres Heinz im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 0Letzter Beitrag: 15.12.10, 23:10 -
Portlet in Netbeans mit Woodstockkomponenten
Von melly_ im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 1Letzter Beitrag: 21.10.08, 18:43 -
Fehlermeldung: package javax.portlet does not exist
Von melly_ im Forum Java GrundlagenAntworten: 3Letzter Beitrag: 13.10.08, 22:55





Zitieren
Login





