Pie Chart Label Link Lines

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
raunakkathuria
Posts: 16
Joined: Wed Dec 22, 2010 5:35 pm
antibot: No, of course not.
Location: India
Contact:

Pie Chart Label Link Lines

Post by raunakkathuria » Wed Dec 22, 2010 8:50 pm

Hi

I need to make a pie chart like the image in link below:

http://www.raunakkathuria.com/images/jf ... echart.jpg

The pie that I have made is shown in link below:

http://www.raunakkathuria.com/images/jf ... actual.jpg

I need to change the look and feel of label link lines and removing them for some section that are very close to the Pie chart sections as shown in Pi

My sample code is

Code: Select all

DefaultPieDataset dataset = createDataset();


        // create a chart...
        JFreeChart chart = ChartFactory.createPieChart(
                "",
                dataset,
                false, // legend?
                true, // tooltips?
                false // URLs?
                );

        chart.setBackgroundPaint(Color.WHITE);

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setSectionPaint("GIC/Stable Value", new Color(154, 152, 101));
        plot.setSectionPaint("Bond", new Color(103, 101, 50));
        plot.setSectionPaint("Balanced", new Color(54, 51, 10));
        plot.setSectionPaint("Lifestyle", new Color(250, 202, 102));
        plot.setSectionPaint("Large US Equity", new Color(204, 102, 2));
        plot.setSectionPaint("Mid US Equity", new Color(102, 52, 2));
        plot.setSectionPaint("Small US Equity", new Color(50, 0, 0));
        plot.setSectionPaint("International", new Color(204, 204, 204));
        plot.setSectionPaint("Emerging Market", new Color(149, 149, 149));
        plot.setSectionPaint("Specialty", new Color(90, 90, 90));
        plot.setSectionPaint("Company Stock", new Color(51, 51, 51));
        plot.setSectionPaint("Window", new Color(0, 0, 0));
        plot.setSectionPaint("Money Market", new Color(205, 203, 154));

        plot.setLabelGenerator(new CustomLabelGenerator());
        plot.setLabelBackgroundPaint(Color.WHITE);
        plot.setLabelOutlinePaint(Color.white);
        plot.setLabelShadowPaint(Color.WHITE);
        plot.setLabelGap(0.0001);
        plot.setLabelLinkMargin(0.0);


        // create and display a frame...
        ChartFrame frame = new ChartFrame("", chart);
        frame.pack();
        frame.setVisible(true);


Thanks
Raunak
Last edited by raunakkathuria on Fri Dec 24, 2010 5:45 am, edited 2 times in total.
Raunak Kathuria

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Re: Bar Chart Label Link Lines

Post by skunk » Wed Dec 22, 2010 9:21 pm

Code: Select all

public void setLabelLinkStyle(PieLabelLinkStyle style)

raunakkathuria
Posts: 16
Joined: Wed Dec 22, 2010 5:35 pm
antibot: No, of course not.
Location: India
Contact:

Re: Bar Chart Label Link Lines

Post by raunakkathuria » Thu Dec 23, 2010 5:35 am

Hi

Thanks for your input and it changed the look of the lines.

Can we do thing like enabling links for some section of PieChart and disabling it for others?

Thanks
Raunak Kathuria

barbarius
Posts: 74
Joined: Tue Jul 27, 2010 9:33 am
antibot: No, of course not.

Re: Bar Chart Label Link Lines

Post by barbarius » Thu Dec 23, 2010 10:11 pm

this thing you have to do manually.

override the method on PiePlot :

Code: Select all

protected void drawLeftLabel(Graphics2D g2, PiePlotState state,
                                 PieLabelRecord record)
on lines 3052, 3057, 3063 (according which style you use) there are some if s. inside each if, by using the parameters that it uses to draw the line (probably just the starting and ending point would be enough which are :targetX, targetY and linkX, linkY), calculate the distance and if its less than you want just dont draw it. but dont forget that that minimum distance of yours might be relative to the chart size.

Locked