use of io.jmix.ui.data.impl.ListDataProvider in project jmix by jmix-framework.
the class ChartsSerializationTest method testXYChart.
@Test
public void testXYChart() throws IOException, URISyntaxException {
ListDataProvider dataProvider = new ListDataProvider();
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "ax", 1.0, "ay", 0.5, "bx", 1.0, "by", 2.2)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "ax", 2.0, "ay", 1.3, "bx", 2.0, "by", 4.9)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "ax", 3.0, "ay", 2.3, "bx", 3.0, "by", 5.1)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "ax", 4.0, "ay", 2.8, "bx", 4.0, "by", 5.3)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "ax", 5.0, "ay", 3.5, "bx", 5.0, "by", 6.1)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "ax", 6.0, "ay", 5.1, "bx", 6.0, "by", 8.3)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "ax", 7.0, "ay", 6.7, "bx", 7.0, "by", 10.5)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "8", "ax", 8.0, "ay", 8.0, "bx", 8.0, "by", 12.3)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "9", "ax", 9.0, "ay", 8.9, "bx", 9.0, "by", 14.5)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "10", "ax", 10.0, "ay", 9.7, "bx", 10.0, "by", 15.0)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "11", "ax", 11.0, "ay", 10.4, "bx", 11.0, "by", 18.8)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "12", "ax", 12.0, "ay", 11.7, "bx", 12.0, "by", 19.0)));
AbstractChart chart = new XYChartModelImpl().setDataProvider(dataProvider).setStartDuration(1.0).setMarginLeft(64).setMarginBottom(60).setChartCursor(new Cursor()).setChartScrollbar(new Scrollbar()).addGraphs(new Graph().setBullet(BulletType.TRIANGLE_UP).setLineAlpha(0.0).setXField("ax").setYField("ay").setLineColor(Color.valueOf("#FF6600")).setFillAlphas(0.0), new Graph().setBullet(BulletType.TRIANGLE_DOWN).setLineAlpha(0.0).setXField("bx").setYField("by").setLineColor(Color.valueOf("#FCD202")).setFillAlphas(0.0)).addTrendLines(new TrendLine().setFinalValue(12.0).setFinalXValue(12.0).setInitialValue(2.0).setInitialXValue(1.0).setLineColor(Color.valueOf("#FF6600")), new TrendLine().setFinalValue(19.0).setFinalXValue(12.0).setInitialValue(1.0).setInitialXValue(1.0).setLineColor(Color.valueOf("#FCD202"))).addValueAxes(new ValueAxis().setAxisAlpha(0.0).setDashLength(1).setTitle("X Axis").setPosition(Position.BOTTOM), new ValueAxis().setAxisAlpha(0.0).setDashLength(1).setTitle("Y Axis").setPosition(Position.LEFT));
ChartSerializer serializer = getTestSerializer();
String json = serializer.serialize(chart);
String expected = readFile("XYChart.json");
assertEquals(prettyJson(expected), prettyJson(json));
}
use of io.jmix.ui.data.impl.ListDataProvider in project jmix by jmix-framework.
the class ChartsSerializationTest method testPieChart.
@Test
public void testPieChart() throws IOException, URISyntaxException {
DataProvider dataProvider = new ListDataProvider();
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "country", "Czech Republic", "litres", 256.9)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "country", "Ireland", "litres", 131.1)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "country", "Germany", "litres", 115.8)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "country", "Australia", "litres", 109.9)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "country", "Austria", "litres", 108.3)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "country", "UK", "litres", 65.0)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "country", "Belgium", "litres", 40.0)));
AbstractChart chart = new PieChartModelImpl().setDataProvider(dataProvider).setDepth3D(15).setAngle(30).setValueField("litres").setTitleField("country").setBalloonText("[[title]] - [[percents]]%").setLegend(new Legend().setMarkerType(MarkerType.CIRCLE).setPosition(LegendPosition.RIGHT).setMarginRight(80).setAutoMargins(false)).setExport(new Export());
ChartSerializer serializer = getTestSerializer();
String json = serializer.serialize(chart);
String expected = readFile("PieChart.json");
assertEquals(prettyJson(expected), prettyJson(json));
}
Aggregations