问题
I am creating a Stack Bar chart with ApplicationName on x axis and UserName on Y axis. I am using:
CategoryDataset stackDataset = DatasetUtilities.createCategoryDataset("Users","App", double[][]data);
It populates the StackBarchart labelling User1, User2 ,User3 on Y axis and similarly App1, App2 etc on X-axis.
Problem: I have an arraylist of userName and applicationName like:
userName = [Max, John,Willy]
appname =[Google, Fb, Twitter]
And these names i have to populate instead of user1 or app1. I have searched something to do this but i am unable to implement this . The code used will be
CategoryDataset stackDataset = createCategoryDataset(java.lang.Comparable[] rowKeys, java.lang.Comparable[] columnKeys, double[][] data)
Any help will be appericiable.
回答1:
There is a version of CategoryDataset that accepts arrays as a parameter, your call shold look like this
String[] userName = new String[] {"Max", "John","Willy"};
String[] appname =new String[] {"Google", "Fb", "Twitter"};
double[][] data = new double[][] {{2,5,3},{2,6,7},{3,5,6}};
return DatasetUtilities.createCategoryDataset(userName,appname,data);

If you are user JFreeChart 1.0.14 createCategoryDataset
is an overloaded method:

You need to use this set of parameters
public static CategoryDataset createCategoryDataset(Comparable[] rowKeys,
Comparable[] columnKeys, double[][] data)
Remember that String
implements Comparable<String>
so you can use a String[]
来源:https://stackoverflow.com/questions/18917150/usage-of-datasetutilities-createcategorydataset-in-jfreechart-in-java