use of org.jfree.ui.RectangleInsets in project MSEC by Tencent.
the class Tools method generateFullDayChart.
public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
if (data[0].getValues().length != 1440) {
return "data size invalid";
}
if (data.length > 1) {
if (data[1].getValues() == null || data[1].getValues().length != 1440) {
return "data 1 invalid";
}
}
XYDataset xydataset = createDataset(data);
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);
try {
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
//线条
xyplot.setRangeGridlinePaint(ChartColor.GRAY);
xyplot.setBackgroundPaint(ChartColor.WHITE);
xyplot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
//去掉边框
xyplot.setOutlinePaint(null);
//横轴
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("H"));
//水平底部标题
dateaxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
dateaxis.setLabelPaint(ChartColor.black);
dateaxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
dateaxis.setTickLabelPaint(ChartColor.black);
GregorianCalendar endgc = (GregorianCalendar) gc.clone();
endgc.add(GregorianCalendar.DATE, 1);
dateaxis.setMaximumDate(endgc.getTime());
dateaxis.setTickMarksVisible(true);
dateaxis.setTickMarkInsideLength(5);
dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
//dateaxis.setVerticalTickLabels(true);
dateaxis.setLabel("");
//纵轴
//获取柱状
ValueAxis rangeAxis = xyplot.getRangeAxis();
rangeAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
rangeAxis.setLabelPaint(ChartColor.black);
rangeAxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
rangeAxis.setTickLabelPaint(ChartColor.black);
rangeAxis.setLowerBound(0);
rangeAxis.setUpperBound(Tools.upperBound(data[0].getMax()));
NumberAxis numAxis = (NumberAxis) rangeAxis;
numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//图例
jfreechart.getLegend().setItemFont(new Font("微软雅黑", Font.PLAIN, 12));
jfreechart.getLegend().setItemPaint(ChartColor.black);
//去掉边框
jfreechart.getLegend().setBorder(0, 0, 0, 0);
//标题
//设置标题字体
jfreechart.getTitle().setFont(new Font("微软雅黑", Font.BOLD, 16));
jfreechart.getTitle().setPaint(ChartColor.black);
int w = 500;
int h = 300;
ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
return "success";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
use of org.jfree.ui.RectangleInsets in project MSEC by Tencent.
the class Tools method generateDaysChart.
public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart, String title, int duration) {
if (data.size() == 0) {
return "data size invalid";
}
int date = Integer.parseInt(data.get(0).getDate());
GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100);
XYDataset xydataset = createDaysDataset(data, startgc, chart);
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);
try {
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
//线条
xyplot.setRangeGridlinePaint(ChartColor.GRAY);
xyplot.setBackgroundPaint(ChartColor.WHITE);
xyplot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
//去掉边框
xyplot.setOutlinePaint(null);
//横轴
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd"));
//水平底部标题
dateaxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
dateaxis.setLabelPaint(ChartColor.black);
dateaxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
dateaxis.setTickLabelPaint(ChartColor.black);
dateaxis.setMinimumDate(startgc.getTime());
GregorianCalendar endgc = (GregorianCalendar) startgc.clone();
endgc.add(GregorianCalendar.DATE, duration);
dateaxis.setMaximumDate(endgc.getTime());
dateaxis.setTickMarksVisible(true);
dateaxis.setTickMarkInsideLength(5);
dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
//dateaxis.setVerticalTickLabels(true);
dateaxis.setLabel("");
//纵轴
//获取柱状
ValueAxis rangeAxis = xyplot.getRangeAxis();
rangeAxis.setLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
rangeAxis.setLabelPaint(ChartColor.black);
rangeAxis.setTickLabelFont(new Font("微软雅黑", Font.PLAIN, 14));
rangeAxis.setTickLabelPaint(ChartColor.black);
rangeAxis.setLowerBound(0);
rangeAxis.setUpperBound(Tools.upperBound(chart.getMax()));
NumberAxis numAxis = (NumberAxis) rangeAxis;
numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//图例
jfreechart.getLegend().setItemFont(new Font("微软雅黑", Font.PLAIN, 12));
jfreechart.getLegend().setItemPaint(ChartColor.black);
//去掉边框
jfreechart.getLegend().setBorder(0, 0, 0, 0);
//标题
//设置标题字体
jfreechart.getTitle().setFont(new Font("微软雅黑", Font.BOLD, 16));
jfreechart.getTitle().setPaint(ChartColor.black);
int w = 500;
int h = 300;
ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
return "success";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
}
use of org.jfree.ui.RectangleInsets in project EnrichmentMapApp by BaderLab.
the class ChartUtil method createHeatStripsLegend.
@SuppressWarnings("serial")
public static JFreeChart createHeatStripsLegend(List<EMDataSet> dataSets, ChartOptions options) {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
int total = dataSets.size();
int v = total / -2;
for (int i = 0; i < total; i++) {
// Just to make sure there is always a bar for each data set name
if (v == 0.0)
v = 1;
dataset.addValue(v++, options.getData().toString(), dataSets.get(i).getName());
}
final JFreeChart chart = ChartFactory.createBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, PlotOrientation.VERTICAL, // include legend
false, // tooltips
true, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setBackgroundPaint(UIManager.getColor("Table.background"));
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(true);
domainAxis.setAxisLineVisible(false);
domainAxis.setTickMarksVisible(false);
domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
domainAxis.setLabelPaint(UIManager.getColor("Label.foreground"));
domainAxis.setMaximumCategoryLabelLines(1);
domainAxis.setCategoryMargin(0.0);
if (total > 4) {
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setMaximumCategoryLabelWidthRatio(0.5f);
} else {
domainAxis.setMaximumCategoryLabelLines(2);
}
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
if (// UP, ZERO, DOWN:
colors == null || colors.size() < 3)
colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
List<Color> itemColors = new ArrayList<>();
for (int i = 0; i < total; i++) {
Number n = dataset.getValue(options.getData().toString(), dataSets.get(i).getName());
itemColors.add(ColorUtil.getColor(n.doubleValue(), -total, total, colors.get(2), colors.get(1), colors.get(0)));
}
final BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(int row, int column) {
return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
}
};
plot.setRenderer(renderer);
renderer.setBarPainter(new StandardBarPainter());
renderer.setDrawBarOutline(true);
renderer.setShadowVisible(false);
renderer.setItemMargin(0.0);
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
return chart;
}
use of org.jfree.ui.RectangleInsets in project cubrid-manager by CUBRID.
the class CombinedBarTimeSeriesChart method createSeriesChart.
/**
* Create the series chart
*
* @return an instance of series chart
*/
private JFreeChart createSeriesChart() {
if (isAreaRender) {
seriesdataset = createTableSeriesDataset();
} else {
seriesdataset = createTimeSeriesDataset();
}
JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", seriesdataset, false, false, false);
chart.setBorderVisible(false);
chart.setBorderStroke(new BasicStroke(0.0f));
//plot
XYPlot xyplot = (XYPlot) chart.getPlot();
xyplot.setOutlineVisible(false);
RectangleInsets rectangleInsets = new RectangleInsets();
xyplot.setAxisOffset(rectangleInsets);
xyplot.setDomainGridlineStroke(new BasicStroke(0.4f));
xyplot.setRangeGridlineStroke(new BasicStroke(0.4f));
xyplot.setBackgroundPaint(Color.BLACK);
xyplot.setDomainGridlinePaint(new Color(0, 128, 64));
xyplot.setRangeGridlinePaint(new Color(0, 128, 64));
if (isAreaRender) {
XYAreaRenderer2 render = new StackedXYAreaRenderer2();
render.setSeriesPaint(0, Color.GREEN);
render.setSeriesPaint(1, Color.RED);
xyplot.setRenderer(render);
} else {
XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) xyplot.getRenderer();
render.setSeriesPaint(0, Color.GREEN);
render.setSeriesPaint(1, Color.RED);
}
//dateAxis
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setFixedAutoRange(300000d);
dateaxis.setLowerMargin(0.0D);
dateaxis.setUpperMargin(0.0D);
dateaxis.setVisible(isShowSeriesAxis);
numberaxis = (NumberAxis) xyplot.getRangeAxis();
numberaxis.setVisible(isShowSeriesAxis);
numberaxis.setRange(0 - 0.5, barMax + 0.5);
return chart;
}
use of org.jfree.ui.RectangleInsets in project processdash by dtuma.
the class RadarPlot method initialise.
private void initialise() {
this.interiorGap = DEFAULT_INTERIOR_GAP;
// this.circular = true;
this.radius = DEFAULT_RADIUS;
this.showAxisLabels = true;
this.axisLabelFont = DEFAULT_AXIS_LABEL_FONT;
this.axisLabelPaint = DEFAULT_AXIS_LABEL_PAINT;
this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
// this.itemLabelGenerator = null;
// this.urlGenerator = null;
this.plotLinePaint = ADAPTIVE_COLORING;
this.axisPaint = Color.black;
this.axisStroke = DEFAULT_OUTLINE_STROKE;
this.gridLinePaint = Color.lightGray;
this.gridLineStroke = DEFAULT_OUTLINE_STROKE;
this.plotLineStroke = DEFAULT_LINE_STROKE;
setForegroundAlpha(0.5f);
setInsets(new RectangleInsets(0, 5, 5, 5));
}
Aggregations