List of usage examples for org.jfree.chart.axis CategoryAxis addCategoryLabelToolTip
public void addCategoryLabelToolTip(Comparable category, String tooltip)
From source file:org.talend.dataprofiler.chart.ChartDecorator.java
/** * DOC bZhou Comment method "decorateCategoryPlot". * /* www . j a v a2 s . c o m*/ * @param chart */ public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) { CategoryPlot plot = chart.getCategoryPlot(); CategoryItemRenderer render = plot.getRenderer(); CategoryAxis domainAxis = plot.getDomainAxis(); // ADD msjian TDQ-5111 2012-4-9: set something look it well domainAxis.setCategoryMargin(0.1); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); domainAxis.setCategoryLabelPositionOffset(10); // TDQ-5111~ ValueAxis valueAxis = plot.getRangeAxis(); Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$ render.setBaseItemLabelFont(font); // MOD zshen 10998: change the font name 2010-01-16 font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$ valueAxis.setLabelFont(font); font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$ domainAxis.setTickLabelFont(font); valueAxis.setTickLabelFont(font); setLegendFont(chart); font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$ TextTitle title = chart.getTitle(); if (title != null) { title.setFont(font); } font = null; if (render instanceof BarRenderer) { CategoryDataset dataset = chart.getCategoryPlot().getDataset(); if (dataset != null) { int rowCount = dataset.getRowCount(); List<?> columnKeys = dataset.getColumnKeys(); if (!isContainCJKCharacter(columnKeys.toArray())) { domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$ } ((BarRenderer) render).setItemMargin(-0.40 * rowCount); // TDQ-12621 add Tooltip for Lable for (Object colKey : columnKeys) { domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString()); } } domainAxis.setUpperMargin(0.1); // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..." domainAxis.setMaximumCategoryLabelLines(1); // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well // not do this when the bar is horizontal Orientation if (orientation == null) { ((BarRenderer) render).setMaximumBarWidth(0.2); } // TDQ-5111~ } // ~10998 }
From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java
/** * Refreshes the waterfall display with the specified analysis data * @param Analyzed data from aro core.//from ww w.ja v a 2 s . c o m */ public void refresh(AROTraceData aModel) { this.popup.refresh(null, 0); this.popup.setVisible(false); double range = DEFAULT_TIMELINE; // Create sorted list of request/response pairs List<WaterfallCategory> categoryList = new ArrayList<WaterfallCategory>(); if (aModel != null && aModel.getAnalyzerResult() != null) { this.traceDuration = aModel.getAnalyzerResult().getTraceresult().getTraceDuration(); // add 20% to make sure labels close to the right edge of the screen are visible this.traceDuration *= 1.2; range = Math.min(this.traceDuration, DEFAULT_TIMELINE); for (Session tcpSession : aModel.getAnalyzerResult().getSessionlist()) { Session thisSession = tcpSession; if (!tcpSession.isUDP()) { for (HttpRequestResponseInfo reqResInfo : tcpSession.getRequestResponseInfo()) { if (reqResInfo.getDirection() == HttpDirection.REQUEST && reqResInfo.getWaterfallInfos() != null) { categoryList.add(new WaterfallCategory(reqResInfo, thisSession)); } } } } // Sort and set index Collections.sort(categoryList); int index = 0; for (WaterfallCategory wCategory : categoryList) { wCategory.setIndex(++index); } } // Horizontal scroll bar used to scroll through trace duration JScrollBar hScrollBar = getHorizontalScroll(); hScrollBar.setMaximum((int) Math.ceil(this.traceDuration)); // Set the visible time range setTimeRange(0, range); CategoryAxis cAxis = getCategoryAxis(); cAxis.clearCategoryLabelToolTips(); // Build the dataset DefaultCategoryDataset underlying = new DefaultCategoryDataset(); for (WaterfallCategory wfc : categoryList) { RequestResponseTimeline rrTimeLine = wfc.getReqResp().getWaterfallInfos(); underlying.addValue(rrTimeLine.getStartTime(), Waterfall.BEFORE, wfc); underlying.addValue(rrTimeLine.getDnsLookupDuration(), Waterfall.DNS_LOOKUP, wfc); underlying.addValue(rrTimeLine.getInitialConnDuration(), Waterfall.INITIAL_CONNECTION, wfc); underlying.addValue(rrTimeLine.getSslNegotiationDuration(), Waterfall.SSL_NEGOTIATION, wfc); underlying.addValue(rrTimeLine.getRequestDuration(), Waterfall.REQUEST_TIME, wfc); underlying.addValue(rrTimeLine.getTimeToFirstByte(), Waterfall.TIME_TO_FIRST_BYTE, wfc); underlying.addValue(rrTimeLine.getContentDownloadDuration(), Waterfall.CONTENT_DOWNLOAD, wfc); underlying.addValue(null, Waterfall.HTTP_3XX_REDIRECTION, wfc); underlying.addValue(null, Waterfall.HTTP_4XX_CLIENTERROR, wfc); int code = wfc.getReqResp().getAssocReqResp().getStatusCode(); double endTime = this.traceDuration - rrTimeLine.getStartTime() - rrTimeLine.getTotalTime(); if (code >= 300 && code < 400) { underlying.addValue(endTime, Waterfall.AFTER_3XX, wfc); } else if (code >= 400) { underlying.addValue(endTime, Waterfall.AFTER_4XX, wfc); } else { underlying.addValue(endTime, Waterfall.AFTER, wfc); } cAxis.addCategoryLabelToolTip(wfc, wfc.getTooltip()); } // Vertical scroll bar is used to scroll through data JScrollBar vScrollBar = getVerticalScroll(); int count = underlying.getColumnCount(); vScrollBar.setValue(0); vScrollBar.setMaximum(count); vScrollBar.setVisibleAmount(count > 0 ? this.dataset.getMaximumCategoryCount() - 1 / count : 1); // Add the dataset to the plot CategoryPlot plot = getChartPanel().getChart().getCategoryPlot(); this.dataset = new SlidingCategoryDataset(underlying, 0, CATEGORY_MAX_COUNT); plot.setDataset(this.dataset); // Place proper colors on renderer for waterfall states final CategoryItemRenderer renderer = plot.getRenderer(); for (Object obj : underlying.getRowKeys()) { Waterfall wFall = (Waterfall) obj; int index = underlying.getRowIndex(wFall); Color paint; switch (wFall) { case DNS_LOOKUP: paint = dnsLoolupColor; break; case INITIAL_CONNECTION: paint = initiaConnColor; break; case SSL_NEGOTIATION: paint = sslNegColor; break; case REQUEST_TIME: paint = requestTimeColor; break; case TIME_TO_FIRST_BYTE: paint = firstByteTimeColor; break; case CONTENT_DOWNLOAD: paint = contentDownloadColor; break; case AFTER_3XX: paint = noneColor; renderer.setSeriesItemLabelPaint(index, threexColor); renderer.setSeriesVisibleInLegend(index, false); break; case AFTER_4XX: paint = noneColor; renderer.setSeriesItemLabelPaint(index, fourxColor); renderer.setSeriesVisibleInLegend(index, false); break; case HTTP_3XX_REDIRECTION: paint = threexColor; break; case HTTP_4XX_CLIENTERROR: paint = fourxColor; break; default: renderer.setSeriesItemLabelPaint(index, Color.black); renderer.setSeriesVisibleInLegend(index, false); paint = noneColor; } renderer.setSeriesPaint(index, paint); } // Adding the label at the end of bars renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() { private static final long serialVersionUID = 1L; @Override public String generateLabel(CategoryDataset dataset, int row, int column) { if (Waterfall.AFTER == dataset.getRowKey(row) || Waterfall.AFTER_3XX == dataset.getRowKey(row) || Waterfall.AFTER_4XX == dataset.getRowKey(row)) { WaterfallCategory waterfallItem = (WaterfallCategory) dataset.getColumnKey(column); RequestResponseTimeline waterfallInfos = waterfallItem.getReqResp().getWaterfallInfos(); DecimalFormat formatter = new DecimalFormat("#.##"); int code = waterfallItem.getReqResp().getAssocReqResp().getStatusCode(); return MessageFormat.format(ResourceBundleHelper.getMessageString("waterfall.totalTime"), formatter.format(waterfallInfos.getTotalTime()), code > 0 ? waterfallItem.getReqResp().getScheme() + " " + code : ResourceBundleHelper.getMessageString("waterfall.unknownCode")); } return null; } }); }