Search code examples
javachartsjfreechartjcchart

how to display many legends for chart on the image


I have to show all the legends created for the chart on the image when converting the chart into image.but the number of legends are much due to which the the legends are cut from the bottom and only few legends appear on the image.

So please can any body tell me how solve this problem


Solution

  • To create image of chart for JCChart I use snapshot(JCChart,int) method of JCChart, it will return the image of the chart. So to display all the legends we will have to overide the snapshot method as follows

    public Image snapshot(JCChart chart,int num_legends){
    Image image = chart.createImage(chart.getSize().width, chart.getSize().height+
    (chart.getLegend().getSymbolSize()+4)*num_legends);
    if(image != null)
    {
    Graphics g = image.getGraphics();
    g.setClip(0, 0, chart.getSize().width,
    chart.getSize().height+chart.getSize().height+
    (chart.getLegend().getSymbolSize()+4)*num_legends);
    chart.paint(g);
    }
    return image;
    }