如何使用jFreeChart格式化极简主义图表?

时间:2014-04-03 18:23:44

标签: charts jfreechart

我生成一个透明的图表,可以通过它看到网页的背景。

到目前为止,我已经完成了这项工作(为简洁起见,省略了数据集的填充):

lineChartObject=ChartFactory.createLineChart("Title","Legend","Amount",line_chart_dataset,PlotOrientation.VERTICAL,true,true,false);
    CategoryPlot p = lineChartObject.getCategoryPlot();

    Color trans = new Color(0xFF, 0xFF, 0xFF, 0);
    lineChartObject.setBackgroundPaint(trans);
    p.setBackgroundPaint(trans);

    for (int i=0;i<=3;i++){
        lineChartObject.getCategoryPlot().getRenderer().setSeriesStroke(i, new BasicStroke(3.0f));
        lineChartObject.getCategoryPlot().getRenderer().setBaseItemLabelsVisible(false);
    }

提出这个:

enter image description here

我无法找到方法:

  • 删除小区边框(1)
  • 去除leyend的边框并使其透明(3)
  • 使X轴(2)上的标签智能化,因为Y轴的标签为(A)。 Y轴的标签自身空间,以免混乱图形,例如,如果我将图形渲染得更小,它将显示更少的标签,如下所示:

修改: X标签域是日期。

enter image description here

1 个答案:

答案 0 :(得分:3)

对于(1)尝试:

plot.setOutlineVisible(false);

对于(2),沿x轴具有太多类别的常见原因是数据实际上是数字,在这种情况下,您应该使用XYPlot而不是CategoryPlot。使用XYPlot时,x轴刻度的调整方式与y轴的调整方式相同。

从OP编辑:使用带有TimeSeriesCollection的TimeSeriesChart作为XYDataSet完成了工作! (想说X域是日期)

对于(3)尝试:

LegendTitle legend = chart.getLegend();
legend.setFrame(BlockBorder.NONE);
legend.setBackgroundPaint(new Color(0, 0, 0, 0));