Search in sources :

Example 11 with MapDataItem

use of io.jmix.ui.data.impl.MapDataItem in project jmix by jmix-framework.

the class StockChartLoader method loadChartData.

protected void loadChartData(StockChart chart, Element element) {
    Element dataProvider = element.element("data");
    if (dataProvider != null) {
        for (Object data : dataProvider.elements("dataSet")) {
            Element dataElement = (Element) data;
            String dataSetId = dataElement.attributeValue("id");
            if (StringUtils.isNotEmpty(dataSetId)) {
                ListDataProvider listDataProvider = new ListDataProvider();
                for (Object item : dataElement.elements("item")) {
                    Element itemElement = (Element) item;
                    MapDataItem mapDataItem = new MapDataItem();
                    for (Element property : itemElement.elements("property")) {
                        mapDataItem = loadDataItem(property, mapDataItem);
                    }
                    listDataProvider.addItem(mapDataItem);
                }
                chart.getDataSet(dataSetId).setDataProvider(listDataProvider);
            }
        }
    }
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Element(org.dom4j.Element) MapDataItem(io.jmix.ui.data.impl.MapDataItem)

Example 12 with MapDataItem

use of io.jmix.ui.data.impl.MapDataItem in project jmix by jmix-framework.

the class StockChartSerializationTest method dateValueVolume.

private MapDataItem dateValueVolume(Integer id, Date date, Long value, Long volume) {
    MapDataItem dateValueVolume = new MapDataItem();
    dateValueVolume.add("id", id);
    dateValueVolume.add("date", date);
    dateValueVolume.add("value", value);
    dateValueVolume.add("volume", volume);
    return dateValueVolume;
}
Also used : MapDataItem(io.jmix.ui.data.impl.MapDataItem)

Example 13 with MapDataItem

use of io.jmix.ui.data.impl.MapDataItem 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 14 with MapDataItem

use of io.jmix.ui.data.impl.MapDataItem 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

MapDataItem (io.jmix.ui.data.impl.MapDataItem)14 ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)9 ChartSerializer (io.jmix.charts.widget.amcharts.serialization.ChartSerializer)3 Element (org.dom4j.Element)3 Test (org.junit.jupiter.api.Test)3 Scrollbar (io.jmix.charts.model.Scrollbar)2 ValueAxis (io.jmix.charts.model.axis.ValueAxis)2 Cursor (io.jmix.charts.model.cursor.Cursor)2 Export (io.jmix.charts.model.export.Export)2 Graph (io.jmix.charts.model.graph.Graph)2 DataProvider (io.jmix.ui.data.DataProvider)2 CategoryAxis (io.jmix.charts.model.axis.CategoryAxis)1 Legend (io.jmix.charts.model.legend.Legend)1 TrendLine (io.jmix.charts.model.trendline.TrendLine)1 FormatStrings (io.jmix.core.metamodel.datatype.FormatStrings)1 Subscribe (io.jmix.ui.screen.Subscribe)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1