Search in sources :

Example 16 with ListDataProvider

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));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Graph(io.jmix.charts.model.graph.Graph) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) ValueAxis(io.jmix.charts.model.axis.ValueAxis) TrendLine(io.jmix.charts.model.trendline.TrendLine) Cursor(io.jmix.charts.model.cursor.Cursor) MapDataItem(io.jmix.ui.data.impl.MapDataItem) Scrollbar(io.jmix.charts.model.Scrollbar) Test(org.junit.jupiter.api.Test)

Example 17 with ListDataProvider

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));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) DataProvider(io.jmix.ui.data.DataProvider) ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Legend(io.jmix.charts.model.legend.Legend) ChartSerializer(io.jmix.charts.widget.amcharts.serialization.ChartSerializer) Export(io.jmix.charts.model.export.Export) MapDataItem(io.jmix.ui.data.impl.MapDataItem) Test(org.junit.jupiter.api.Test)

Aggregations

ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)17 MapDataItem (io.jmix.ui.data.impl.MapDataItem)9 Test (org.junit.jupiter.api.Test)6 Export (io.jmix.charts.model.export.Export)5 Subscribe (io.jmix.ui.screen.Subscribe)5 ChartSerializer (io.jmix.charts.widget.amcharts.serialization.ChartSerializer)4 Scrollbar (io.jmix.charts.model.Scrollbar)3 ValueAxis (io.jmix.charts.model.axis.ValueAxis)3 Cursor (io.jmix.charts.model.cursor.Cursor)3 Graph (io.jmix.charts.model.graph.Graph)3 Element (org.dom4j.Element)3 StockChartGroup (io.jmix.charts.model.chart.impl.StockChartGroup)2 StockPanel (io.jmix.charts.model.chart.impl.StockPanel)2 DataSet (io.jmix.charts.model.dataset.DataSet)2 FieldMapping (io.jmix.charts.model.dataset.FieldMapping)2 Period (io.jmix.charts.model.period.Period)2 PeriodSelector (io.jmix.charts.model.period.PeriodSelector)2 ChartCursorSettings (io.jmix.charts.model.settings.ChartCursorSettings)2 ChartScrollbarSettings (io.jmix.charts.model.settings.ChartScrollbarSettings)2 StockGraph (io.jmix.charts.model.stock.StockGraph)2