Refresh a piechart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
kkt8
Posts: 2
Joined: Wed May 18, 2011 1:19 pm
antibot: No, of course not.

Refresh a piechart

Post by kkt8 » Wed May 18, 2011 1:30 pm

Hello,

I work with JFreeChart in a plugin eclipse, in a viewPart.
I want to create a chart from a file informations, the first time it's ok :

Code: Select all

private String executableToChart = null;
Composite parentView;
ChartComposite compoChart = null;
JFreeChart chart = null;

public void createPartControl(Composite parent) {
		
		parentView = parent;
		if(executableToChart == null){
			ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
			if(selection instanceof TreeSelection){
				TreeSelection ts = (TreeSelection)selection;
				TreePath[] treePath = ts.getPaths();
				Object oFile = treePath[0].getFirstSegment();
				if ((oFile != null) && (oFile instanceof IBinary)) {
					IBinary bin = (IBinary) oFile;
					IResource f = bin.getResource();
					executableToChart = f.getLocation().toString();
				}
			}
		}

	createChart(executableToChart, 1);		    
	}

private void createChart(String exe, int i){
		DefaultPieDataset data = createDataSet(exe,i);
	 
	    //create a chart...
		chart = null;
		chart=ChartFactory.createPieChart( "SamplePieChart", data, true/*legend?*/,true/*tooltips?*/, false/*URLs?*/);
		
	   compoChart = null;
	   compoChart = new ChartComposite(parentView, SWT.NONE, chart, true);
	    
	}
// just for test : simply data
private DefaultPieDataset createDataSet(String executable, int test){
		//create a dataset...
	    DefaultPieDataset data=new DefaultPieDataset();
	    if(test == 1){
		    data.setValue("Category1",43.2);
		    data.setValue("Category2",27.9);
		    data.setValue("Category3",79.5);
	    }
	    if(test == 2){
	    	data.setValue("OtherCategory1",63.2);
		    data.setValue("OtherCategory2",17.9);
		    data.setValue("OtherCategory3",29.5);
	    }
	    
	    return data;
	}
But, with if the file selection changes, I want to update the chart, empty the view and redraw a new chart with news informations :

Code: Select all

public void showSelection(ISelection selection) {
		// change le projet actif
		if (!selection.isEmpty()) {
			if (selection instanceof TreeSelection) {
				TreeSelection ts = (TreeSelection)selection;
				TreePath[] treePath = ts.getPaths();
				Object oFile = ts.getFirstElement();
				if (oFile != null) {
						if (oFile instanceof IBinary) {
							IBinary bin = (IBinary) oFile;
							IResource f = bin.getResource();
							setExecutable(f.getLocation().toString());
							createChart(f.getLocation().toString(), 2);
				}}
			}
		}
	}
This code has effects : nothing immedialtly and if I minimaze the view and and after maximize, I've 2 chart with differents dataset.

HOW can I empty the view first and redraw a new chart in my viewPart ?
thank you :)

Locked