0

I have 6 numbers, all from 0-100. I need to put the inside a chart, I already have the codes for the chart but don't know how to link it to my array. the chart uses bars. This is my code below, its the average of two other arrays that I have:

public static void computeResults(double[] examMarks, double[] courseworkmarks)
{
    double avgMarks[] =new double[examMarks.length];
    System.out.println ("The total average of each module is ");
    for(int i=0;i<avgMarks.length;i++){
        int cwWeighting=40;
        avgMarks[i]=(examMarks[i]*(100-cwWeighting)+courseworkmarks[i]*cwWeighting)/100;
        System.out.print(avgMarks[i] + "\t" );
    }
}
4

1 回答 1

2

这是一个基本示例,说明如何在 JFreechart 中设置条形图的值,这可能会对您有所帮助,具体取决于您用于创建图表的库:

public class BarChartExample {
public static void main(String[] args) {
// Create a simple Bar chart

double[] dub = {12.2, 15.4, 18.3, 9.3, 7.7};    //Array 
String[] student = {"Bob", "Dave", "William", "Boris", "Rick"}; //Array

DefaultCategoryDataset dataset = new DefaultCategoryDataset(); //Create dataset
for(int i = 0; i < dub.length; i++){
dataset.setValue(dub[i], "Marks", student[i]); //Setting the values
}

JFreeChart chart = ChartFactory.createBarChart3D("Goal comparison",
"Marks", "Students", dataset, PlotOrientation.VERTICAL,
false, true, false); //Chart creation
try {
ChartUtilities.saveChartAsJPEG(new File("D:\\Users\\user2777005\\Desktop\\Barchart.jpg"), chart,     500, 300);
} catch (IOException e) {
System.err.println("Problem occurred creating chart.");
}}}

祝你好运!

于 2013-11-08T08:56:21.470 回答