Question

I generate a transparent chart that lets the background of a web page be seen through it.

So far I've done this (omited the populating of dataset for brevity):

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);
    }

Which renders this:

enter image description here

I cannot find a way of:

  • Removing border of plot (1)
  • Removing border of leyend as well as making it transparent (3)
  • Making the labels on the X axis (2) to behave intelligently as the labels of Y axis do (A). Labels of Y axis space themselves so as to not clutter the graph, for example if I rendered the graph smaller, it would show fewer labels, like this:

Edit: X label domain is dates.

enter image description here

Was it helpful?

Solution

For (1) try:

plot.setOutlineVisible(false);

For (2), a common reason for having too many categories along the x-axis is that the data is actually numerical, in which case you should be using XYPlot rather than CategoryPlot. With XYPlot, the x-axis scale adjusts in the same way that the y-axis does.

Edit from OP: Using a TimeSeriesChart with a TimeSeriesCollection as XYDataSet did the work! (fotgot to say X domain is dates)

For (3) try:

LegendTitle legend = chart.getLegend();
legend.setFrame(BlockBorder.NONE);
legend.setBackgroundPaint(new Color(0, 0, 0, 0));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top