
hi i want to visualize free disk spaces of machines as a bar chart.thanks.

import java.io.*;
import java.text.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.axis.*;
import org.jfree.data.category.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
public class ChartDemo{
public static void main(String arg[]){
File f1=new File("C:\\");
File f2=new File("D:\\");
long d1 = f1.getFreeSpace()/1024/1024;
long d2 = f2.getFreeSpace()/1024/1024;
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(d1, "Free Space", "C");
dataset.setValue(d2, "Free Space", "D");
JFreeChart chart = ChartFactory.createBarChart("Bar Chart","Drives", "Free Space(in MB)", dataset,
PlotOrientation.VERTICAL, false,true, false);
CategoryPlot p = chart.getCategoryPlot();
NumberAxis rangeAxis = (NumberAxis) p.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer = (BarRenderer) p.getRenderer();
DecimalFormat decimalformat1 = new DecimalFormat("##");
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
renderer.setItemLabelsVisible(true);
chart.getCategoryPlot().setRenderer(renderer);
ChartFrame frame=new ChartFrame("Bar Chart",chart);
frame.setVisible(true);
frame.setSize(350,450);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.