2

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?

1 Answer 1

1

The signature for DefaultPieDataset.setValue() is

setValue(java.lang.Comparable key, double value)

So I don't think an array of chars allows for "Comparable" values in said array.
An array of String might (String implementing the Comparable interface, which is why your first example is working).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.