I have trouble loading an array via a simple for loop into JFreeChart's DataSet. For example this will world perfectly fine:
private PieDataset createDataset() {
DefaultPieDataset result = new DefaultPieDataset();
result.setValue("Linux", 29);
result.setValue("Mac", 20);
result.setValue("Windows", 51);
return result;
}
However if I try to implement the code above with arrays by looping through each element of the array it will not work:
private PieDataset createDataset() {
DefaultPieDataset result = new DefaultPieDataset();
int[] array1 = new int[]{29,20,51};
char[] array2 = new char[]{"Linux", "Mac", "Windows"};
for (int i = 0; i < 3; i++) {
result.setValue(array2[i], array1[i]);
}
return result;
}
Any idea where I went wrong?