我有6个数字,全部来自0-100。我需要把图表放在里面,我已经有了图表的代码,但不知道如何将它链接到我的数组。图表使用条形图。这是我下面的代码,它是我拥有的其他两个数组的平均值:
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" );
}
}
答案 0 :(得分: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.");
}}}
祝你好运!