use of org.jfree.chart.title.LegendTitle in project bamboobsc by billchen198318.
the class CommonPieChartAction method fillChart.
private void fillChart(String title, List<String> names, List<String> colors, List<Float> values) throws Exception {
DefaultPieDataset data = new DefaultPieDataset();
for (int ix = 0; ix < names.size(); ix++) {
data.setValue(names.get(ix), values.get(ix));
}
this.chart = ChartFactory.createPieChart3D(title, data, true, true, false);
LegendTitle legend = this.chart.getLegend();
legend.setItemFont(new Font("", Font.TRUETYPE_FONT, 9));
PiePlot plot = (PiePlot) this.chart.getPlot();
plot.setCircular(true);
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.5f);
plot.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
this.setPlotColor(plot, names, colors);
this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}
use of org.jfree.chart.title.LegendTitle in project processdash by dtuma.
the class CGIChartBase method writeContents.
/** Generate CGI chart output. */
@Override
protected void writeContents() throws IOException {
// get the data for display
buildData();
chromeless = (parameters.get("chromeless") != null);
JFreeChart chart = createChart();
int width = getIntSetting("width");
int height = getIntSetting("height");
Color initGradColor = getColorSetting("initGradColor");
Color finalGradColor = getColorSetting("finalGradColor");
chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor));
if (parameters.get("hideOutline") != null)
chart.getPlot().setOutlinePaint(INVISIBLE);
String title = getSetting("title");
if (chromeless || title == null || title.length() == 0)
chart.setTitle((TextTitle) null);
else {
chart.setTitle(Translator.translate(title));
String titleFontSize = getSetting("titleFontSize");
if (titleFontSize != null)
try {
float fontSize = Float.parseFloat(titleFontSize);
TextTitle t = chart.getTitle();
t.setFont(t.getFont().deriveFont(fontSize));
} catch (Exception tfe) {
}
}
if (chromeless || parameters.get("hideLegend") != null)
chart.removeLegend();
else {
LegendTitle l = chart.getLegend();
String legendFontSize = getSetting("legendFontSize");
if (l != null && legendFontSize != null)
try {
float fontSize = Float.parseFloat(legendFontSize);
l.setItemFont(l.getItemFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
}
chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message"));
Axis xAxis = getHorizontalAxis(chart);
if (xAxis != null) {
if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) {
xAxis.setTickLabelsVisible(false);
} else if (parameters.get("tickLabelFontSize") != null || parameters.get("xTickLabelFontSize") != null) {
String tfs = getParameter("xTickLabelFontSize");
if (tfs == null)
tfs = getParameter("tickLabelFontSize");
float fontSize = Float.parseFloat(tfs);
xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize));
}
}
Axis yAxis = getVerticalAxis(chart);
if (yAxis != null) {
if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) {
yAxis.setTickLabelsVisible(false);
} else if (parameters.get("tickLabelFontSize") != null || parameters.get("yTickLabelFontSize") != null) {
String tfs = getParameter("yTickLabelFontSize");
if (tfs == null)
tfs = getParameter("tickLabelFontSize");
float fontSize = Float.parseFloat(tfs);
yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize));
}
}
String axisFontSize = getSetting("axisLabelFontSize");
if (axisFontSize != null)
try {
float fontSize = Float.parseFloat(axisFontSize);
if (xAxis != null)
xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize));
if (yAxis != null)
yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize));
} catch (Exception afs) {
}
ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null);
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = img.createGraphics();
if ("auto".equals(getSetting("titleFontSize")))
maybeAdjustTitleFontSize(chart, g2, width);
chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info);
g2.dispose();
String outputFormat = getSetting("outputFormat");
OutputStream imgOut;
if (isHtmlMode()) {
imgOut = PngCache.getOutputStream();
} else {
imgOut = outStream;
}
ImageIO.write(img, outputFormat, imgOut);
imgOut.flush();
imgOut.close();
if (isHtmlMode())
writeImageHtml(width, height, imgOut.hashCode(), info);
}
use of org.jfree.chart.title.LegendTitle in project tdq-studio-se by Talend.
the class ChartDecorator method setLegendFont.
/**
* if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma".
*
* @param chart
*/
private static void setLegendFont(JFreeChart chart) {
Font font;
LegendTitle legend = chart.getLegend();
if (legend != null) {
// $NON-NLS-1$
font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
// get legend label to judge if it contains CJK.
LegendItemSource[] sources = legend.getSources();
Set<String> itemLabels = new HashSet<String>();
for (LegendItemSource source : sources) {
LegendItemCollection legendItems = source.getLegendItems();
for (int i = 0; i < legendItems.getItemCount(); i++) {
String label = legendItems.get(i).getLabel();
if (label != null) {
itemLabels.add(label);
}
}
}
if (isContainCJKCharacter(itemLabels.toArray())) {
font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
}
legend.setItemFont(font);
}
}
use of org.jfree.chart.title.LegendTitle in project nimbus by nimbus-org.
the class JFreeChartFactoryService method createChart.
// JFreeChartFactoryのJavaDoc
public JFreeChart createChart(ChartCondition chartCondition) throws JFreeChartCreateException {
Plot plot = null;
try {
plot = plotFactory.createPlot(chartCondition.getPlotConditions());
} catch (PlotCreateException e) {
// プロット生成失敗
throw new JFreeChartCreateException(e);
}
JFreeChart chart = copyJFreeChart(plot);
// タイトルの設定
if (chartCondition.getTitle() != null && (chartCondition.getTitleFontName() != null || chartCondition.getTitleFontStyle() != Integer.MIN_VALUE || chartCondition.getTitleFontSize() != Integer.MIN_VALUE)) {
Font newFont = null;
TextTitle orgTitle = chart.getTitle();
if (orgTitle != null) {
newFont = mergeFont(orgTitle.getFont(), chartCondition.getTitleFontName(), chartCondition.getTitleFontStyle(), chartCondition.getTitleFontSize());
}
if (newFont != null) {
chart.setTitle(new TextTitle(chartCondition.getTitle(), newFont));
} else {
chart.setTitle(chartCondition.getTitle());
}
} else if (chartCondition.getTitle() != null) {
// タイトル文字列のみ設定された
chart.setTitle(chartCondition.getTitle());
}
if (chart.getSubtitleCount() > 0) {
List subList = chart.getSubtitles();
String defaultFontName = chartCondition.getDefaultSubtitleFontName();
int defaultFontStyle = chartCondition.getDefaultSubtitleFontStyle();
int defaultFontSize = chartCondition.getDefaultSubtitleFontSize();
if (defaultFontName != null || defaultFontStyle != Integer.MIN_VALUE || defaultFontSize != Integer.MIN_VALUE) {
// サブタイトルすべてにデフォルトのフォントを設定する。
for (int i = 0; i < subList.size(); i++) {
Object subtitle = subList.get(i);
if (subtitle instanceof LegendTitle) {
LegendTitle legendTitle = (LegendTitle) subtitle;
legendTitle.setItemFont(mergeFont(legendTitle.getItemFont(), defaultFontName, defaultFontStyle, defaultFontSize));
} else if (subtitle instanceof TextTitle) {
TextTitle textTitle = (TextTitle) subtitle;
textTitle.setFont(mergeFont(textTitle.getFont(), defaultFontName, defaultFontStyle, defaultFontSize));
}
}
} else {
// 個々のサブタイトルにフォントを設定
for (int i = 0; i < subList.size(); i++) {
String subFontName = chartCondition.getSubtitleFontName(i);
int subFontStyle = chartCondition.getSubtitleFontStyle(i);
int subFontSize = chartCondition.getSubtitleFontSize(i);
if (subFontName == null && subFontStyle == Integer.MIN_VALUE && subFontSize == Integer.MIN_VALUE) {
continue;
}
Title subtitle = chart.getSubtitle(i);
if (subtitle instanceof LegendTitle) {
LegendTitle legendTitle = (LegendTitle) subtitle;
legendTitle.setItemFont(mergeFont(legendTitle.getItemFont(), subFontName, subFontStyle, subFontSize));
} else if (subtitle instanceof TextTitle) {
TextTitle textTitle = (TextTitle) subtitle;
textTitle.setFont(mergeFont(textTitle.getFont(), subFontName, subFontStyle, subFontSize));
}
}
}
}
return chart;
}
use of org.jfree.chart.title.LegendTitle in project mafscaling by vimsh.
the class MafRescale method createGraghPanel.
private void createGraghPanel(JPanel dataPanel) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
mafChartPanel = new MafChartPanel(chart, this);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
gbl_chartPanel.insets = insets0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 2;
dataPanel.add(mafChartPanel.getChartPanel(), gbl_chartPanel);
XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesStroke(1, stroke);
lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setSeriesShape(1, ShapeUtilities.createUpTriangle((float) 2.5));
ValueAxis mafvDomain = new NumberAxis(XAxisName);
ValueAxis mafgsRange = new NumberAxis(YAxisName);
XYSeriesCollection lineDataset = new XYSeriesCollection();
lineDataset.addSeries(currMafData);
lineDataset.addSeries(corrMafData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, mafvDomain);
plot.setRangeAxis(0, mafgsRange);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
Aggregations