Search in sources :

Example 6 with TextTitle

use of org.jfree.chart.title.TextTitle in project opennms by OpenNMS.

the class ChartUtils method addSubTitles.

/**
 * @param chartConfig
 * @param barChart
 */
private static void addSubTitles(BarChart chartConfig, JFreeChart barChart) {
    Iterator<SubTitle> it;
    /*
         * Add subtitles.
         */
    for (it = chartConfig.getSubTitleCollection().iterator(); it.hasNext(); ) {
        SubTitle subTitle = (SubTitle) it.next();
        Title title = subTitle.getTitle();
        String value = title.getValue();
        barChart.addSubtitle(new TextTitle(value));
    }
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) Title(org.opennms.netmgt.config.charts.Title) TextTitle(org.jfree.chart.title.TextTitle) SubTitle(org.opennms.netmgt.config.charts.SubTitle) SubTitle(org.opennms.netmgt.config.charts.SubTitle)

Example 7 with TextTitle

use of org.jfree.chart.title.TextTitle in project GT by Tencent.

the class AbstractRealTimeLineChart method setSubTitle.

/**
	 * 添加文字副标题
	* @Title: setSubTitle  
	* @Description:   
	* @param title 
	* void 
	* @throws
	 */
public void setSubTitle(String title) {
    Title curSubTitle = new TextTitle(title);
    if (lastSubTile == null) {
        chart.addSubtitle(curSubTitle);
    } else {
        chart.removeSubtitle(lastSubTile);
        chart.addSubtitle(curSubTitle);
    }
    lastSubTile = curSubTitle;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) Title(org.jfree.chart.title.Title) TextTitle(org.jfree.chart.title.TextTitle)

Example 8 with TextTitle

use of org.jfree.chart.title.TextTitle in project ice by Netflix.

the class BasicWeeklyCostEmailService method createImage.

private File createImage(ApplicationGroup appgroup) throws IOException {
    Map<String, Double> costs = Maps.newHashMap();
    DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0);
    Interval interval = new Interval(end.minusWeeks(numWeeks), end);
    for (Product product : products) {
        List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product);
        if (resourceGroups.size() == 0) {
            continue;
        }
        DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly);
        if (dataManager == null) {
            continue;
        }
        TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null, resourceGroups);
        Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none, false);
        for (Tag tag : data.keySet()) {
            for (int week = 0; week < numWeeks; week++) {
                String key = tag + "|" + week;
                if (costs.containsKey(key))
                    costs.put(key, data.get(tag)[week] + costs.get(key));
                else
                    costs.put(key, data.get(tag)[week]);
            }
        }
    }
    boolean hasData = false;
    for (Map.Entry<String, Double> entry : costs.entrySet()) {
        if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) {
            hasData = true;
            break;
        }
    }
    if (!hasData)
        return null;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (Product product : products) {
        for (int week = 0; week < numWeeks; week++) {
            String weekStr = String.format("%s - %s week", formatter.print(end.minusWeeks(numWeeks - week)).substring(5), formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5));
            dataset.addValue(costs.get(product + "|" + week), product.name, weekStr);
        }
    }
    JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "", "Costs", dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer();
    renderer.setItemLabelAnchorOffset(10.0);
    TextTitle title = chart.getTitle();
    title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3)));
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() {

        public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
            return costFormatter.format(dataset.getValue(row, column));
        }
    });
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setNumberFormatOverride(costFormatter);
    BufferedImage image = chart.createBufferedImage(1200, 400);
    File outputfile = File.createTempFile("awscost", "png");
    ImageIO.write(image, "png", outputfile);
    return outputfile;
}
Also used : StandardCategoryItemLabelGenerator(org.jfree.chart.labels.StandardCategoryItemLabelGenerator) NumberAxis(org.jfree.chart.axis.NumberAxis) DateTime(org.joda.time.DateTime) BufferedImage(java.awt.image.BufferedImage) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) TextTitle(org.jfree.chart.title.TextTitle) BarRenderer3D(org.jfree.chart.renderer.category.BarRenderer3D) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) File(java.io.File) Interval(org.joda.time.Interval)

Example 9 with TextTitle

use of org.jfree.chart.title.TextTitle in project series-rest-api by 52North.

the class ChartIoHandler method addNotice.

private void addNotice(JFreeChart chart) {
    TextTitle notice = new TextTitle();
    String msg = i18n.get("msg.io.chart.notice");
    if (msg != null && !msg.isEmpty()) {
        notice.setText(msg);
        notice.setPaint(Color.BLACK);
        notice.setFont(LabelConstants.FONT_LABEL_SMALL);
        notice.setPosition(RectangleEdge.BOTTOM);
        notice.setHorizontalAlignment(HorizontalAlignment.RIGHT);
        notice.setVerticalAlignment(VerticalAlignment.BOTTOM);
        notice.setPadding(new RectangleInsets(0, 0, 20, 20));
        chart.addSubtitle(notice);
    }
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) RectangleInsets(org.jfree.ui.RectangleInsets)

Example 10 with TextTitle

use of org.jfree.chart.title.TextTitle in project cubrid-manager by CUBRID.

the class ChartCompositePart method fireChartSetting.

/**
	 * This method is responsible for preparing data for ChartSettingDlg and
	 * dealing with the results of chartSettingDlg
	 *
	 */
public void fireChartSetting() {
    TextTitle title = chart.getTitle();
    if (title.getBackgroundPaint() == null) {
        ttlBgColor = trimPaintColor(chart.getBackgroundPaint().toString());
    } else {
        ttlBgColor = trimPaintColor(title.getBackgroundPaint().toString());
    }
    Font titleFont = title.getFont();
    String ttlFontName = titleFont.getFontName();
    int ttlFontSize = titleFont.getSize();
    String ttlFontColor = trimPaintColor(title.getPaint().toString());
    // plot
    XYPlot plot = chart.getXYPlot();
    String plotBgColor = trimPaintColor(plot.getBackgroundPaint().toString());
    String plotDomainGridColor = trimPaintColor(plot.getDomainGridlinePaint().toString());
    String plotRangGridColor = trimPaintColor(plot.getRangeGridlinePaint().toString());
    String plotDateAxisColor = trimPaintColor(plot.getRangeAxis().getAxisLinePaint().toString());
    String plotNumberAxisColor = trimPaintColor(plot.getDomainAxis().getAxisLinePaint().toString());
    ChartSettingDlg chartSettingDlg = new ChartSettingDlg(composite.getShell());
    if (ttlBgColor != null) {
        chartSettingDlg.setTtlBgColor(ttlBgColor);
    }
    // title
    chartSettingDlg.setTtlFontName(ttlFontName);
    chartSettingDlg.setTtlFontSize(ttlFontSize);
    chartSettingDlg.setTtlFontColor(ttlFontColor);
    // plot appearance
    chartSettingDlg.setPlotBgColor(plotBgColor);
    chartSettingDlg.setPlotDomainGridColor(plotDomainGridColor);
    chartSettingDlg.setPlotRangGridColor(plotRangGridColor);
    chartSettingDlg.setPlotDateAxisColor(plotDateAxisColor);
    chartSettingDlg.setPlotNumberAxisColor(plotNumberAxisColor);
    // series
    chartSettingDlg.setSettingMap(settingMap);
    // history path
    chartSettingDlg.setHistoryPath(historyPath);
    chartSettingDlg.setHistoryFileName(historyFileName);
    if (chartSettingDlg.open() == Dialog.OK) {
        // title
        ttlBgColor = chartSettingDlg.getTtlBgColor();
        ttlFontName = chartSettingDlg.getTtlFontName();
        ttlFontSize = chartSettingDlg.getTtlFontSize();
        ttlFontColor = chartSettingDlg.getTtlFontColor();
        // plot
        plotBgColor = chartSettingDlg.getPlotBgColor();
        plotDomainGridColor = chartSettingDlg.getPlotDomainGridColor();
        plotRangGridColor = chartSettingDlg.getPlotRangGridColor();
        plotDateAxisColor = chartSettingDlg.getPlotDateAxisColor();
        plotNumberAxisColor = chartSettingDlg.getPlotNumberAxisColor();
        // history path
        String newHistoryPath = chartSettingDlg.getHistoryPath();
        isChangedHistoryPath = historyPath.equals(newHistoryPath) ? false : true;
        if (isChangedHistoryPath) {
            historyPath = newHistoryPath;
        }
        int red = 0;
        int green = 0;
        int blue = 0;
        if (ttlBgColor != null) {
            red = getColorElem(ttlBgColor, 0);
            green = getColorElem(ttlBgColor, 1);
            blue = getColorElem(ttlBgColor, 2);
            title.setBackgroundPaint(new Color(red, green, blue));
        }
        titleFont = new Font(ttlFontName, 1, ttlFontSize);
        title.setFont(titleFont);
        red = getColorElem(ttlFontColor, 0);
        green = getColorElem(ttlFontColor, 1);
        blue = getColorElem(ttlFontColor, 2);
        title.setPaint(new Color(red, green, blue));
        red = getColorElem(plotBgColor, 0);
        green = getColorElem(plotBgColor, 1);
        blue = getColorElem(plotBgColor, 2);
        plot.setBackgroundPaint(new Color(red, green, blue));
        red = getColorElem(plotDomainGridColor, 0);
        green = getColorElem(plotDomainGridColor, 1);
        blue = getColorElem(plotDomainGridColor, 2);
        plot.setDomainGridlinePaint(new Color(red, green, blue));
        red = getColorElem(plotRangGridColor, 0);
        green = getColorElem(plotRangGridColor, 1);
        blue = getColorElem(plotRangGridColor, 2);
        plot.setRangeGridlinePaint(new Color(red, green, blue));
        red = getColorElem(plotDateAxisColor, 0);
        green = getColorElem(plotDateAxisColor, 1);
        blue = getColorElem(plotDateAxisColor, 2);
        plot.getRangeAxis().setAxisLinePaint(new Color(red, green, blue));
        red = getColorElem(plotNumberAxisColor, 0);
        green = getColorElem(plotNumberAxisColor, 1);
        blue = getColorElem(plotNumberAxisColor, 2);
        plot.getDomainAxis().setAxisLinePaint(new Color(red, green, blue));
        // series
        settingMap = chartSettingDlg.getSettingMap();
        updateSettingSeries();
    }
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) XYPlot(org.jfree.chart.plot.XYPlot) Color(java.awt.Color) CommonUITool.trimPaintColor(com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor) Font(java.awt.Font)

Aggregations

TextTitle (org.jfree.chart.title.TextTitle)12 Font (java.awt.Font)4 JFreeChart (org.jfree.chart.JFreeChart)4 Color (java.awt.Color)3 PiePlot (org.jfree.chart.plot.PiePlot)3 CommonUITool.trimPaintColor (com.cubrid.common.ui.spi.util.CommonUITool.trimPaintColor)2 BufferedImage (java.awt.image.BufferedImage)2 BigDecimal (java.math.BigDecimal)2 DecimalFormat (java.text.DecimalFormat)2 NumberFormat (java.text.NumberFormat)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 NumberAxis (org.jfree.chart.axis.NumberAxis)2 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)2 CategoryPlot (org.jfree.chart.plot.CategoryPlot)2 XYPlot (org.jfree.chart.plot.XYPlot)2 LegendTitle (org.jfree.chart.title.LegendTitle)2 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)2 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)2 GradientPaint (java.awt.GradientPaint)1 Graphics2D (java.awt.Graphics2D)1