On Jun 23, 2013, at 8:56 PM, Ryan McCune wrote:
> I am attempting to add a bar chart using BarChartGenerator. I have a small array and would like to chart each entry.
>
> JFreeChart adds series to bar charts using datasets, of which I have created. But the BarChartGenerator's addSeries method in MASON uses an array of Objects, and I'm unclear how the array correlates to what is charted. I passed my array, and only the length was charted.
>
> I have had success plotting Time Series Charts. Is there an example of adding series data for a Histogram or Bar Chart?
So this question got me modifying the Pie Chart and Bar Chart facilities tonight, cleaning them up and adding some gizmos. The result is out on SVN right now. But the big gizmo that I think you're looking for I decided against adding.
So here's the deal. The addSeries method adds one of three items:
- an array of doubles and an array of Strings. The doubles represent the Pie/Bar chart amounts, and the Strings are their corresponding labels.
- an array of Objects. We group the Objects into subarrays where each subarray contains all copies of a given unique object. For example, if the Object array is [A, B, C, A, A, B], we divide into [A, A, A], [B, B], and [C]. Then the elements in the Bar/Pie chart are the sizes of these arrays, and the labels are the toString() method called on each element (A, B, or C in this example).
- a Collection. This is handled just like the array of Objects.
The addSeries method creates the series. But you are responsible for updating it: it does NOT update the underlying data to reflect changes in your arrays or Collections. To update the data, you call updateSeries(...).
Note: before you add a Bar Chart, think carefully about whether you want this, or in fact really want a Histogram. They are different beasts.
Sean