Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

java - StackedBarChart row key is not added to DefaultCategoryDataSet

I have two entity Classes: A and B. A has B entities, and I have a Map defined in the following format: Map<A, List<B>.

I want to add all map data to DefaultCategoryDataset with following code. For example, if have 5 A and each A has 4 B, I want to have 25 row keys. (A entity number * (A entityNumber + B entity number in each A). A Row key that stores A class must be same width; all other rows that store B entities must have same width. To succeed in this, I am giving the same values while adding A row keys((double) 1 / (1 + bResultList .size()), and giving smaller values while adding A row keys((double) 1 / (1 + bResultList .size() + 6).

DefaultCategoryDataset dataset = new DefaultCategoryDataset();
/** for each workpoint */
for (A aResult : map.keySet()) {
    List<B> bResultList = map.get(aResult);
    dataset.addValue(
        (double) 1 / (1 + bResultList.size()),
        "WorkPoint " + aResult.getTimeStep(),
        "WP T=" + aResult.getTimeStep());
    /** for each contingency result */
    for (B bResult : bResultList) {
        dataset.addValue(
            (double) 1 / (1 + bResultList.size() + 6),
            bResult.getName(),
            "WP T=" + aResult.getTimeStep());
    }
}

But when I add all map data to data set all row keys are not stored. When I debug, Dataset only has 9 rows. (A1,B1,B2,B3,B4,A2,A3,A4,A5) Only B entities of first A entity is stored as row keys. Other B entities of other A entity is not stored in database.

But when I display graph, all data is displayed in graph but in wrong order. Order is following.

A1-B1-B2-B3-B4
B1-B2-B3-B4-A2
B1-B2-B3-B4-A3
B1-B2-B3-B4-A4
B1-B2-B3-B4-A5

I want to display like

A1-B1-B2-B3-B4
A2-B1-B2-B3-B4
A3-B1-B2-B3-B4
A4-B1-B2-B3-B4
A5-B1-B2-B3-B4
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Absent your sscce the problem is not apparent. It may help to compare your data set to a typical CategoryDataset such as this one that has distinct series (row) and category (column) keys. Also, adding a CategoryItemLabelGenerator may aid debugging.

renderer.setBaseItemLabelGenerator(
    new StandardCategoryItemLabelGenerator(
        "{0} {1} {2}", NumberFormat.getInstance()));
renderer.setBaseItemLabelsVisible(true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...