List of usage examples for org.jfree.data.general DefaultPieDataset setValue
public void setValue(Comparable key, double value)
From source file:dbseer.gui.chart.DBSeerChartFactory.java
public static DefaultPieDataset getPieDataset(String chartName, DBSeerDataSet dataset) throws Exception { StatisticalPackageRunner runner = DBSeerGUI.runner; runner.eval("[title legends Xdata Ydata Xlabel Ylabel timestamp] = plotter.plot" + chartName + ";"); String title = runner.getVariableString("title"); Object[] legends = (Object[]) runner.getVariableCell("legends"); Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata"); Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata"); String xLabel = runner.getVariableString("Xlabel"); String yLabel = runner.getVariableString("Ylabel"); timestamp = runner.getVariableDouble("timestamp"); DefaultPieDataset pieDataSet = new DefaultPieDataset(); int numLegends = legends.length; int numXCellArray = xCellArray.length; int numYCellArray = yCellArray.length; int dataCount = 0; if (numXCellArray != numYCellArray) { JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.", "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE); return null; }//from w w w .j av a2 s. c o m final java.util.List<String> transactionTypeNames = dataset.getTransactionTypeNames(); for (int i = 0; i < numYCellArray; ++i) { double[] xArray = (double[]) xCellArray[i]; runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});"); runner.eval("yArray = Ydata{" + (i + 1) + "};"); double[] yArraySize = runner.getVariableDouble("yArraySize"); double[] yArray = runner.getVariableDouble("yArray"); int xLength = xArray.length; int row = (int) yArraySize[0]; int col = (int) yArraySize[1]; for (int c = 0; c < col; ++c) { if (c < transactionTypeNames.size()) { String name = transactionTypeNames.get(c); if (!name.isEmpty()) { pieDataSet.setValue(name, yArray[c]); } else { pieDataSet.setValue("Transaction Type " + (c + 1), yArray[c]); } } } } return pieDataSet; }
From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed DefaultPieDataset piedataset = new DefaultPieDataset(); int rowcount = applianceTable.getRowCount(); for (int i = 0; i <= rowcount - 1; i++) { Sensor sensor = (Sensor) applianceTable.getValueAt(i, 0); int j = sensor.getNumberWatt() * sensor.getHours(); piedataset.setValue(sensor.getSensorType(), j); }/*from w ww . ja va 2 s .co m*/ JFreeChart freechart = ChartFactory.createPieChart("Pie Chart for Carbon Monoxide Levels", piedataset, true, true, Locale.ENGLISH); PiePlot plot = (PiePlot) freechart.getPlot(); ChartFrame frame = new ChartFrame("Pie Chart", freechart); frame.setVisible(true); frame.setSize(500, 500); }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getNoChapterPie() { JFreeChart chart;//from w ww .j a v a2s .c o m DefaultPieDataset ds = new DefaultPieDataset(); Integer numChapter = Helpers.getGroup("Chapter").getNumMembers(); ds.setValue("in a chapter", numChapter); ds.setValue("not in a chapter", Helpers.getGroup("Org").getNumMembers() - numChapter); chart = ChartFactory.createPieChart("Chapter Membership Breakdown", ds, false, false, false); PiePlot plot = ((PiePlot) chart.getPlot()); StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0.0%")); plot.setLabelGenerator(n); return chart; }
From source file:in.co.itasca.geu.Main.java
private PieDataset createDataset(GraphData[] models) { DefaultPieDataset result = new DefaultPieDataset(); int total = 0; for (int i = 0; i < models.length; i++) { GraphData model = models[i];//from w w w. j a va 2s.c om String amountStr = model.getAmount(); int amount = Integer.parseInt(amountStr); total = total + amount; } for (int i = 0; i < models.length; i++) { GraphData model = models[i]; String amountStr = model.getAmount(); int amount = Integer.parseInt(amountStr); int percentage = amount * 100 / total; result.setValue(model.getName(), percentage); } // result.setValue("2013", 29); // result.setValue("2012", 20); // result.setValue("2011", 51); return result; }
From source file:userinterface.EnvironmentRole.PollutionCheckJPanel.java
private void btnSincereCarOwnerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSincereCarOwnerActionPerformed DefaultPieDataset pieDataset = new DefaultPieDataset(); // int f = 0; for (Organization organization : enterprise.getOrganizationDirectory().getOrganizationList()) { if (organization instanceof CarOwnerOrganization) { for (UserAccount userAccount : ((CarOwnerOrganization) organization).getUserAccountDirectory() .getUserAccountList()) { int f = 0; for (WorkRequest request : environmentOrganization.getWorkQueue().getWorkRequestList()) { if (request.getSender() == userAccount) { f = f + ((EnvironmentWorkRequest) request).getFine(); }/*from w w w .j a v a 2 s . c o m*/ } pieDataset.setValue(userAccount.getEmployee().getName(), f); } } } JFrame frame = new JFrame("PieChart"); frame.setSize(600, 400); frame.setVisible(true); JFreeChart pieChart = ChartFactory.createPieChart("Best Car Owner in terms of fine charged", // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? ); ChartPanel cp1 = new ChartPanel(pieChart); frame.getContentPane().add(cp1); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.piecharts.PieCharts.java
public DatasetMap calculateValue() throws Exception { logger.debug("IN"); String res = DataSetAccessFunctions.getDataSetResultFromId(profile, getData(), parametersObject); SourceBean sbRows = SourceBean.fromXMLString(res); SourceBean sbRow = (SourceBean) sbRows.getAttribute("ROW"); List listAtts = sbRow.getContainedAttributes(); DefaultPieDataset dataset = new DefaultPieDataset(); List atts = new Vector(); atts.add(res);// ww w . j a v a 2s . c o m if (name.indexOf("$F{") >= 0) { setTitleParameter(atts); } if (getSubName() != null && getSubName().indexOf("$F") >= 0) { setSubTitleParameter(atts); } for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) { SourceBeanAttribute att = (SourceBeanAttribute) iterator.next(); String name = att.getKey(); String valueS = (String) att.getValue(); //try Double and Integer Conversion Double valueD = null; try { valueD = Double.valueOf(valueS); } catch (Exception e) { } Integer valueI = null; if (valueD == null) { valueI = Integer.valueOf(valueS); } if (name != null && valueD != null) { dataset.setValue(name, valueD); } else if (name != null && valueI != null) { dataset.setValue(name, valueI); } } logger.debug("OUT"); DatasetMap datasets = new DatasetMap(); datasets.addDataset("1", dataset); return datasets; }
From source file:com.ikon.servlet.admin.StatsGraphServlet.java
/** * Generate memory statistics// w w w . j av a2 s . co m * http://casidiablo.net/capturar-informacion-sistema-operativo-java/ */ public JFreeChart osMemStats() throws IOException, ServletException { DefaultPieDataset dataset = new DefaultPieDataset(); Sigar sigar = new Sigar(); String title = null; try { Mem mem = sigar.getMem(); long max = mem.getRam(); long available = mem.getFree(); long total = mem.getTotal(); long used = mem.getUsed(); long free = mem.getFree(); title = "OS memory: " + FormatUtil.formatSize(total); log.debug("OS maximun memory: {}", FormatUtil.formatSize(max)); log.debug("OS available memory: {}", FormatUtil.formatSize(available)); log.debug("OS free memory: {}", FormatUtil.formatSize(free)); log.debug("OS used memory: {}", FormatUtil.formatSize(used)); log.debug("OS total memory: {}", FormatUtil.formatSize(total)); dataset.setValue("Available (" + FormatUtil.formatSize(free) + ")", free * 100 / total); dataset.setValue("Used (" + FormatUtil.formatSize(used) + ")", used * 100 / total); } catch (SigarException se) { title = "OS memory: " + se.getMessage(); } catch (UnsatisfiedLinkError ule) { title = "OS memory: (missing native libraries)"; } return ChartFactory.createPieChart(title, dataset, true, false, false); }
From source file:kobytest.KobyTest.java
public static void conectar() { final int clientId = 1; final int port = 4001; final String host = "127.0.0.1"; //EReader ereader = new EReader(); final EWrapper anyWrapper = new EWrapper() { @Override/* w w w . j a va 2s . c o m*/ public void error(Exception e) { System.out.println("error(exception):" + e.toString()); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void error(String str) { System.out.println("error(string):" + str); //throw new UnsupportedOperationException("Not error yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void error(int id, int errorCode, String errorMsg) { // System.out.println("id:" + id + ". errorcode:" + errorCode + ". msg: " + errorMsg); // throw new UnsupportedOperationException(errorMsg); //To change body of generated methods, choose Tools | Templates. wrapper_error(id, errorCode, errorMsg); } @Override public void connectionClosed() { //JOptionPane.showMessageDialog(null,"Tws cerro flujo de datos", "DATA NULL", JOptionPane.ERROR_MESSAGE); System.out.println("Connection closed"); // throw new UnsupportedOperationException("Not connectionClosed yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickPrice(int tickerId, int field, double price, int canAutoExecute) { if (isDebugConsoleMode) System.out.println("Entra tickPrice"); wrapper_valor(tickerId, field, price); if (isDebugConsoleMode) System.out.println( "Returned tickPrice for :" + tickerId + ". field:" + field + ". Price" + price); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickSize(int tickerId, int field, int size) { if (isDebugConsoleMode) System.out.println("Returned tickSize for :" + tickerId + ". field:" + field + ". size" + size); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickOptionComputation(int tickerId, int field, double impliedVol, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) { if (isDebugConsoleMode) System.out.println("Returned tickOptionComputation for :" + tickerId + ". " + "field:" + field + ". " + "impliedVol" + impliedVol + ". " + "delta " + delta + ". " + "optPrice" + optPrice + ". " + "pvDividend" + pvDividend + ". " + "gamma" + gamma + ". " + "vega" + vega + ". " + "theta" + theta + ". " + "undPrice" + undPrice + ". "); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickGeneric(int tickerId, int tickType, double value) { System.out.println( "Returned tickGeneric for :" + tickerId + ". tickType:" + tickType + ". value" + value); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickString(int tickerId, int tickType, String value) { System.out.println( "Returned tickString for :" + tickerId + ". tickType:" + tickType + ". value" + value); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickEFP(int tickerId, int tickType, double basisPoints, String formattedBasisPoints, double impliedFuture, int holdDays, String futureExpiry, double dividendImpact, double dividendsToExpiry) { if (isDebugConsoleMode) System.out.println("Returned tickGeneric for :" + tickerId + ". " + "basisPoints:" + basisPoints + ". " + "formattedBasisPoints:" + formattedBasisPoints + ". " + "impliedFuture:" + impliedFuture + ". " + "holdDays:" + holdDays + ". " + "futureExpiry:" + futureExpiry + ". " + "dividendImpact:" + dividendImpact + ". " + "dividendsToExpiry:" + dividendsToExpiry + ". "); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void orderStatus(int orderId, String status, int filled, int remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, String whyHeld) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void openOrder(int orderId, Contract contract, Order order, OrderState orderState) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void openOrderEnd() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } // ================================================== // ================================================== // ================================================== // ================================================== Double netLiquidation = 0.0; Double excessLiquidation = 0.0; @Override public void updateAccountValue(String key, String value, String currency, String accountName) { if (semaforo.Semaforo.isDebugMode) System.out.println("TWSClientInterface:updateAccountValue: Key: " + key + " value:" + value + " currency:" + currency + " accountName:" + accountName); switch (key) { case "NetLiquidation": netLiquidation = Double.parseDouble(value); break; case "ExcessLiquidity": excessLiquidation = Double.parseDouble(value); break; } // if (netLiquidation <> 0 && excessLiquidation <> 0 ) { Double temp = ((netLiquidation - excessLiquidation) / netLiquidation) * 100; Controller.getSettings().setPorcentCapital(temp); // // } //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } // ================================================== // ================================================== // ================================================== // ================================================== // ================================================== // ================================================== // ================================================== // ================================================== @Override public void updateAccountTime(String timeStamp) { if (semaforo.Semaforo.isDebugMode) System.out.println("TWSClientInterface:updateAccountTime: " + timeStamp); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void accountDownloadEnd(String accountName) { if (semaforo.Semaforo.isDebugMode) System.out.println("TWSClientInterface:accountDownloadEnd: " + accountName); //listener.guardaNumPos(78); } @Override public void nextValidId(int orderId) { System.out.println("Ya estamos coenctados con el orderId: " + orderId); try { conexion_aceptada_wrapper(); } catch (SQLException ex) { Logger.getLogger(KobyTest.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(KobyTest.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void contractDetails(int reqId, ContractDetails contractDetails) { System.out.println( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + contractDetails.m_summary.m_secType); //To change body of generated methods, choose Tools | Templates. } @Override public void bondContractDetails(int reqId, ContractDetails contractDetails) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void contractDetailsEnd(int reqId) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void execDetails(int reqId, Contract contract, Execution execution) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void execDetailsEnd(int reqId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void updateMktDepth(int tickerId, int position, int operation, int side, double price, int size) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void updateMktDepthL2(int tickerId, int position, String marketMaker, int operation, int side, double price, int size) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void updateNewsBulletin(int msgId, int msgType, String message, String origExchange) { System.out.println("Bulletin news"); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void managedAccounts(String accountsList) { System.out.println("Cuentas: " + accountsList); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void receiveFA(int faDataType, String xml) { System.out.println("Received FA"); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) { if (count >= 0) { if (!date.equals(strWeek)) { Calendar cal = Calendar.getInstance(); int current_day = cal.get(Calendar.DAY_OF_MONTH); int current_month = cal.get(Calendar.MONTH) + 1; int current_year = cal.get(Calendar.YEAR); String fecha = current_year + "-" + current_month + "-" + current_day; DDBB.deleteLowHighFecha(fecha); DDBB.insertLowHigh(symbol_current, fecha, "" + low, "" + high); System.out.println("-------------------------------------" + strWeek); System.out.println("HISTORICAL DATA for order_id: " + reqId); System.out.println("Historical Date: " + date); System.out.println("Historical Open: " + open); System.out.println("Historical high: " + high); System.out.println("Historical low: " + low); System.out.println("Historical close: " + close); System.out.println("Historical volume: " + volume); System.out.println("Historical count: " + count); System.out.println("Historical WAP: " + WAP); System.out.println("Historical hasGaps: " + hasGaps); System.out.println("-------------------------------------"); } else { ResultSet ticks = DDBB.Tickers(); try { while (ticks.next()) { if (reqId == Settings.getTickerID(ticks.getString("name"))) { DDBB.updateHighHighTicker(ticks.getString("name"), high + ""); DDBB.updateLowLowTicker(ticks.getString("name"), low + ""); System.out.println(ticks.getString("name") + "-------------------------------------" + strWeek); System.out.println("HISTORICAL DATA for order_id: " + reqId); System.out.println("Historical Date: " + date); System.out.println("Historical Open: " + open); System.out.println("Historical high: " + high); System.out.println("Historical low: " + low); System.out.println("Historical close: " + close); System.out.println("Historical volume: " + volume); System.out.println("Historical count: " + count); System.out.println("Historical WAP: " + WAP); System.out.println("Historical hasGaps: " + hasGaps); System.out.println("-------------------------------------"); } } } catch (SQLException ex) { Logger.getLogger(KobyTest.class.getName()).log(Level.SEVERE, null, ex); } } } //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. //wrapper_historico(reqId, date, high, low, open, close); } @Override public void scannerParameters(String xml) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void scannerData(int reqId, int rank, ContractDetails contractDetails, String distance, String benchmark, String projection, String legsStr) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void scannerDataEnd(int reqId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void realtimeBar(int reqId, long time, double open, double high, double low, double close, long volume, double wap, int count) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void currentTime(long time) { System.out.println("Current time is: " + time); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void fundamentalData(int reqId, String data) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void deltaNeutralValidation(int reqId, UnderComp underComp) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void tickSnapshotEnd(int reqId) { System.out.println("tickSnapshotEnd: " + reqId); wrapper_snapshot_ended(reqId); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void marketDataType(int reqId, int marketDataType) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void commissionReport(CommissionReport commissionReport) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //###################################### //############ POSITION ################ int numPosiciones = 0; public int numPosicionesTotal = 0; public Map valorPosiciones = new HashMap(); @Override public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, String accountName) { if (contract.m_secType.equals("CFD")) { Semaforo.countCfd++; } if (ticP.isEmpty()) { ticP = contract.m_symbol; positionP = position; strikeP = contract.m_strike; } else { if (ticP.equals(contract.m_symbol)) { if (strikeP > contract.m_strike) { if (positionP > 0) { //el mayor es positivo Bear Semaforo.countBear++; System.out.println(">>>>>countBear>>>>>" + Semaforo.countBear); } else { //ll mayor es negativo Bull Semaforo.countBull++; System.out.println(">>>>>countBull>>>>>" + Semaforo.countBull); } } else { if (position > 0) { //el mayor es positivo Bear Semaforo.countBear++; System.out.println(">>>>>countBear>>>>>" + Semaforo.countBear); } else { //ll mayor es negativo Bull Semaforo.countBull++; System.out.println(">>>>>countBull>>>>>" + Semaforo.countBull); } } } else { ticP = contract.m_symbol; positionP = position; strikeP = contract.m_strike; } } System.out.println("TWSClientInterface:updatePortfolio: " + accountName + " " + contract.m_secType + " " + contract.m_symbol + " " + position + " " + marketPrice + " " + marketValue + " " + averageCost + " " + unrealizedPNL + " " + realizedPNL); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void position(String account, Contract contract, int pos, double avgCost) { semaforo.LogFile.logFile("#### INVOCANDO position: " + contract.m_symbol + " y posicion: " + pos); double avg = (avgCost * pos) + 0.2; ResultSet resGruposOld = DDBB.GruposTickersTicker(contract.m_symbol); try { if (resGruposOld.next()) { DDBB.updateGroupTickerInvertido(contract.m_symbol, (int) avg); } else { DDBB.insertGroupsTickers("", contract.m_symbol, (int) avg); } } catch (SQLException ex) { Logger.getLogger(Groups.class.getName()).log(Level.SEVERE, null, ex); } // System.out.println("ESTE ES EL POS TRAIDO POR TWS: ACCION: " + contract.m_symbol + " y posicion: " + pos); String msg = " ---- Position begin ----\n" + "account = " + account + "\n" + "conid = " + contract.m_conId + "\n" + "symbol = " + contract.m_symbol + "\n" + "secType = " + contract.m_secType + "\n" + "expiry = " + contract.m_expiry + "\n" + "strike = " + contract.m_strike + "\n" + "right = " + contract.m_right + "\n" + "multiplier = " + contract.m_multiplier + "\n" + "exchange = " + contract.m_exchange + "\n" + "primaryExch = " + contract.m_primaryExch + "\n" + "currency = " + contract.m_currency + "\n" + "localSymbol = " + contract.m_localSymbol + "\n" + "tradingClass = " + contract.m_tradingClass + "\n" + "position = " + Util.IntMaxString(pos) + "\n" + "averageCost = " + Util.DoubleMaxString(avgCost) + "\n" + " ---- Position end ----\n"; System.out.println(msg); if (pos > 0) { numPosiciones++; if (contract.m_secType.compareTo("CFD") == 0) valorPosiciones.put(contract.m_symbol, pos); } //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void positionEnd() { semaforo.LogFile.logFile("#### INVOCANDO positionEnd"); segundaPasada++; // connection.reqAccountUpdates(false, "U1523016"); numPosicionesTotal = numPosiciones; if (segundaPasada > 1 && !graficopaint) { Semaforo.cfd = false; Semaforo.bull = false; Semaforo.bear = false; DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); double cfd = 0.0; double bull = 0.0; double bear = 0.0; if (countCfd != 0) cfd = (countCfd * 100) / (countBear + countBull + countCfd); if (countBull != 0) bull = ((countBull * 100) / (countBear + countBull + countCfd)); if (countBear != 0) bear = ((countBear * 100) / (countBear + countBull + countCfd)); Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)"); Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)"); Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)"); DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd)); pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull)); pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear)); JFreeChart chart = null; chart = ChartFactory.createPieChart("", // chart title pieDataset, // data false, // no legend false, // tooltips false // no URL generation ); Semaforo.SemaforoGrafico(chart); graficopaint = true; Semaforo.countBear = 0.0; Semaforo.countBull = 0.0; Semaforo.countCfd = 0.0; System.out.println(":::::::::::::::::::::::::::::::::::::::::::::::::::::::" + segundaPasada + Semaforo.countBear + Semaforo.countBull + Semaforo.countCfd); } else if (segundaPasada >= 2) { Semaforo.cfd = false; Semaforo.bull = false; Semaforo.bear = false; Semaforo.editGrafico(); Semaforo.countBear = 0.0; Semaforo.countBull = 0.0; Semaforo.countCfd = 0.0; // Semaforo.countBear=Semaforo.countBear+5; } System.out.println("+++++" + posiciones); if (semaforo.Semaforo.edit == 0) { Semaforo.finalcountBear = Semaforo.countBear; Semaforo.finalcountBull = Semaforo.countBull; Semaforo.finalcountCfd = Semaforo.countCfd; } semaforo.Semaforo.edit = 1; listener.guardaNumPos(numPosicionesTotal); listener.guardaPosiciones(valorPosiciones); valorPosiciones = new HashMap(); // %30 numPosiciones = 0; //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void accountSummary(int reqId, String account, String tag, String value, String currency) { System.out.println("account summary"); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void accountSummaryEnd(int reqId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void verifyMessageAPI(String apiData) { System.out.println("verifyMessageAPI: " + apiData); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void verifyCompleted(boolean isSuccessful, String errorText) { System.out.println("verifyCompleted: " + errorText); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void displayGroupList(int reqId, String groups) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void displayGroupUpdated(int reqId, String contractInfo) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; // System.out.println("Enter something here : "); new Thread() { @Override public void run() { // super.run(); //To change body of generated methods, choose Tools | Templates. connection = new EClientSocket(anyWrapper); //connection.eConnect(host, port, clientId); connection.eConnect(host, port, clientId); //esperar conexion while (true) { System.out.println("Testing if there's connection"); boolean connected = connection.isConnected(); if (connected) { System.out.println("Conectados ! :"); conexion_iniciada_wrapper(); break; } try { Thread.sleep(50); } catch (InterruptedException ex) { Logger.getLogger(KobyTest.class.getName()).log(Level.SEVERE, null, ex); } } } }.start(); }
From source file:view.statistics.IssueChart.java
private void showChartBtn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showChartBtn1ActionPerformed String option = "" + optionCombo.getSelectedItem(); String chartType = "" + chartCombo.getSelectedItem(); if (option.equals("Blood Components")) { try {/* ww w . ja v a 2s . c om*/ int cryoCount = 0; int ffpCount = 0; int freshBloodCount = 0; int plasmaCount = 0; int plateletsCount = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getIssueInfo(year, month); while (rst.next()) { String type = rst.getString("BloodType"); if (type.equalsIgnoreCase("CRYO")) { cryoCount++; } else if (type.equalsIgnoreCase("FFP")) { ffpCount++; } else if (type.equalsIgnoreCase("Fresh Blood")) { freshBloodCount++; } else if (type.equalsIgnoreCase("Plasma/CSP")) { plasmaCount++; } else if (type.equalsIgnoreCase("Platelets")) { plateletsCount++; } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("CRYO", cryoCount); piedataset.setValue("FFP", ffpCount); piedataset.setValue("Fresh Blood", freshBloodCount); piedataset.setValue("Plasma/CSP", plasmaCount); piedataset.setValue("Platelets", plateletsCount); JFreeChart chart = ChartFactory.createPieChart3D("Issued Blood Components", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(cryoCount, "Issued Values", "CRYO"); dataset.setValue(ffpCount, "Issued Values", "FFP"); dataset.setValue(freshBloodCount, "Issued Values", "Fresh Blood"); dataset.setValue(plasmaCount, "Issued Values", "Plasma/CSP"); dataset.setValue(plateletsCount, "Issued Values", "Platelets"); if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Bloood Components", "Blood Component", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Blood Components", "Blood Component", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "-1Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Blood Groups")) { try { int Apos = 0; int Bpos = 0; int Aneg = 0; int Bneg = 0; int ABpos = 0; int Opos = 0; int ABneg = 0; int Oneg = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getIssueInfo(year, month); while (rst.next()) { String type = rst.getString("BloodGroup"); if (type.equalsIgnoreCase("A+")) { Apos++; } else if (type.equalsIgnoreCase("B+")) { Bpos++; } else if (type.equalsIgnoreCase("A-")) { Aneg++; } else if (type.equalsIgnoreCase("B-")) { Bneg++; } else if (type.equalsIgnoreCase("AB+")) { ABpos++; } else if (type.equalsIgnoreCase("AB-")) { ABneg++; } else if (type.equalsIgnoreCase("O+")) { Opos++; } else if (type.equalsIgnoreCase("O-")) { Oneg++; } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("A+", Apos); piedataset.setValue("A-", Aneg); piedataset.setValue("B+", Bpos); piedataset.setValue("B-", Bneg); piedataset.setValue("AB+", ABpos); piedataset.setValue("AB-", ABneg); piedataset.setValue("O+", Opos); piedataset.setValue("O-", Oneg); JFreeChart chart = ChartFactory.createPieChart3D("Issued Blood Groups", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(Apos, "Issued Values", "A+"); dataset.setValue(Aneg, "Issued Values", "A-"); dataset.setValue(Bpos, "Issued Values", "B+"); dataset.setValue(Bneg, "Issued Values", "B-"); dataset.setValue(ABpos, "Issued Values", "AB+"); dataset.setValue(ABneg, "Issued Values", "AB-"); dataset.setValue(Opos, "Issued Values", "O+"); dataset.setValue(Oneg, "Issued Values", "O-"); if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Bloood Groups", "Blood Group", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Blood Groups", "Blood Group", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "0Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Gender")) { try { int male = 0; int female = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getRequesteeInfo(year, month); while (rst.next()) { String type = rst.getString("Gender"); if (type.equalsIgnoreCase("Male")) { male++; } else if (type.equalsIgnoreCase("Female")) { female++; } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); piedataset.setValue("Male", male); piedataset.setValue("Female", female); JFreeChart chart = ChartFactory.createPieChart3D("Blood Requestees", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(male, "", "Male"); dataset.setValue(female, "", "Female"); if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Blood Requestees", "Gender", "", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Blood Requestees", "Gender", "", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "1Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Hospitals")) { try { String[] hospitals = new String[10]; int[] hospitalCount = new int[10]; int noOfHospitals = 0; ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = SampleDetailsController.getAllHospitals(); while (rst.next()) { hospitals[noOfHospitals] = rst.getString("Name"); hospitalCount[noOfHospitals] = 0; noOfHospitals++; } rst = IssueController.getRequesteeInfo(year, month); while (rst.next()) { String type = rst.getString("Hospital"); for (int i = 0; i < noOfHospitals; i++) { if (type.equalsIgnoreCase(hospitals[i])) { hospitalCount[i]++; } } } if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); for (int i = 0; i < noOfHospitals; i++) { piedataset.setValue(hospitals[i], hospitalCount[i]); } JFreeChart chart = ChartFactory.createPieChart3D("Issued Hospitals", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < noOfHospitals; i++) { dataset.setValue(hospitalCount[i], "Issued Values", hospitals[i]); } if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Hospitals", "Hospital", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Hospitals", "Hospital", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(null, "2Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } else if (option.equals("Age Groups")) { try { int[] ages = new int[10]; for (int i = 0; i < 10; i++) { ages[i] = 0; } ResultSet rst = null; String year = "" + yearCombo.getSelectedItem(); String month = "" + monthCombo.getSelectedItem(); rst = IssueController.getRequesteeInfo(year, month); while (rst.next()) { int age = Integer.parseInt(rst.getString("Age")); if (age <= 10 && age > 0) { ages[0]++; } else if (age <= 20 && age > 10) { ages[1]++; } else if (age <= 30 && age > 20) { ages[2]++; } else if (age <= 40 && age > 30) { ages[3]++; } else if (age <= 50 && age > 40) { ages[4]++; } else if (age <= 60 && age > 50) { ages[5]++; } else if (age <= 70 && age > 60) { ages[6]++; } else if (age <= 80 && age > 70) { ages[7]++; } else if (age <= 90 && age > 80) { ages[8]++; } else if (age <= 100 && age > 90) { ages[9]++; } } rst = IssueController.getRequesteeInfo(year, month); if (chartType.equals("Pie Chart")) { DefaultPieDataset piedataset = new DefaultPieDataset(); for (int i = 0; i < 10; i++) { piedataset.setValue(i * 10 + "-" + (i * 10 + 10), ages[i]); } JFreeChart chart = ChartFactory.createPieChart3D("Issued Age Groups", piedataset, true, true, true); ChartPanel panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int i = 0; i < 10; i++) { dataset.setValue(ages[i], "Issued Values", i * 10 + "-" + (i * 10 + 10)); } if (chartType.equals("Bar Chart")) { JFreeChart chart = ChartFactory.createBarChart3D("Issued Age Groups", "Age Groups", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } else if (chartType.equals("Line Chart")) { JFreeChart chart = ChartFactory.createLineChart3D("Issued Age Groups", "Age Groups", "Issued Values", dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.PINK); chart.getTitle().setPaint(Color.RED); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLUE); ChartPanel panel = new ChartPanel(chart); chartArea.add(panel); panel.setSize(chartArea.getSize()); panel.setVisible(true); } } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "3Data Error!", "Warning!", JOptionPane.OK_OPTION); } catch (ClassNotFoundException ex) { Logger.getLogger(IssueChart.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:kolacer.Kolacer.java
public JFreeChart makePieChart(String nazevGrafu) { JFreeChart graf;/*from ww w.j av a 2s . c om*/ DefaultPieDataset ds = new DefaultPieDataset(); for (Udaj u : udaje) { if (jCHB_nuloveVyskyty.isSelected() || u.pocet > 0) ds.setValue(u.hodnota, u.pocet); } graf = ChartFactory.createPieChart(nazevGrafu, (PieDataset) ds, false, false, false); // legends, tooltips, urls PiePlot plot = (PiePlot) graf.getPlot(); upravPlot(plot); graf.setBackgroundPaint(Barvy.barvaPozadi); graf.setBorderVisible(false); return graf; }