Usage of DatasetUtilities.createCategoryDataset in jfreechart in java

流过昼夜 提交于 2019-12-13 05:01:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!