Search in sources :

Example 6 with ChartModel

use of org.xwiki.chart.model.ChartModel in project xwiki-platform by xwiki.

the class TablePieDatasetBuilderTest method testBuildPieDatasetRowsSeries.

@Test
public void testBuildPieDatasetRowsSeries() throws Exception {
    String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "pie", "range", "B2-D3", "series", "rows"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Dataset dataset = chartModel.getDataset();
    Assert.assertTrue(dataset instanceof PieDataset);
    PieDataset pieDataset = (PieDataset) dataset;
    Assert.assertTrue(pieDataset.getKey(0).equals(" column 2 "));
    Assert.assertTrue(pieDataset.getKey(1).equals(" column 3 "));
    Assert.assertTrue(pieDataset.getKey(2).equals(" column 4"));
    Assert.assertTrue(pieDataset.getValue(0).intValue() == 12);
    Assert.assertTrue(pieDataset.getValue(1).intValue() == 13);
    Assert.assertTrue(pieDataset.getValue(2).intValue() == 14);
}
Also used : PieDataset(org.jfree.data.general.PieDataset) Dataset(org.jfree.data.general.Dataset) PieDataset(org.jfree.data.general.PieDataset) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ChartModel (org.xwiki.chart.model.ChartModel)6 ValueAxis (org.jfree.chart.axis.ValueAxis)4 Dataset (org.jfree.data.general.Dataset)4 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 DateAxis (org.jfree.chart.axis.DateAxis)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 PieDataset (org.jfree.data.general.PieDataset)2 TimeTableXYDataset (org.jfree.data.time.TimeTableXYDataset)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Locale (java.util.Locale)1