Search in sources :

Example 11 with ListDataProvider

use of io.jmix.ui.data.impl.ListDataProvider in project jmix-docs by Haulmont.

the class PolarChart method onInit.

@Subscribe
protected void onInit(InitEvent event) {
    ListDataProvider dataProvider = new ListDataProvider();
    dataProvider.addItem(new MapDataItem().add("direction", "N").add("value", 8.0));
    dataProvider.addItem(new MapDataItem().add("direction", "NE").add("value", 9.0));
    dataProvider.addItem(new MapDataItem().add("direction", "E").add("value", 4.5));
    dataProvider.addItem(new MapDataItem().add("direction", "SE").add("value", 3.5));
    dataProvider.addItem(new MapDataItem().add("direction", "S").add("value", 9.2));
    dataProvider.addItem(new MapDataItem().add("direction", "SW").add("value", 8.4));
    dataProvider.addItem(new MapDataItem().add("direction", "W").add("value", 11.1));
    dataProvider.addItem(new MapDataItem().add("direction", "NW").add("value", 10.0));
    polarChart.setDataProvider(dataProvider);
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) MapDataItem(io.jmix.ui.data.impl.MapDataItem)

Example 12 with ListDataProvider

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

the class GanttChartLoader method loadChartData.

@Override
protected void loadChartData(ChartModel chart, Element element) {
    Element dataSet = element.element("data");
    if (dataSet != null) {
        ListDataProvider listDataProvider = new ListDataProvider();
        for (Object item : dataSet.elements("item")) {
            Element itemElement = (Element) item;
            MapDataItem dataItem = new MapDataItem();
            for (Element property : itemElement.elements("property")) {
                if (property.elements().size() > 0) {
                    List<MapDataItem> innerItems = new ArrayList<>();
                    for (Object innerItem : property.elements("item")) {
                        Element innerItemElement = (Element) innerItem;
                        MapDataItem innerDataItem = new MapDataItem();
                        for (Element innerProperty : innerItemElement.elements("property")) {
                            innerDataItem = loadDataItem(innerProperty, innerDataItem);
                        }
                        innerItems.add(innerDataItem);
                    }
                    dataItem.add(property.attributeValue("name"), innerItems);
                } else {
                    dataItem = loadDataItem(property, dataItem);
                }
            }
            listDataProvider.addItem(dataItem);
            chart.setDataProvider(listDataProvider);
        }
    }
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) MapDataItem(io.jmix.ui.data.impl.MapDataItem)

Example 13 with ListDataProvider

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

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

the class StockChartSerializationTest method testStockChartWithIntradayDatas.

@Test
public void testStockChartWithIntradayDatas() throws ParseException, IOException, URISyntaxException {
    ListDataProvider chartData = new ListDataProvider();
    populateStockDatasourceWithTime(chartData, 40L, 100L);
    StockChartGroup stockChart = new StockChartGroup().setCategoryAxesSettings(new CategoryAxesSettings().setMinPeriod("mm")).addDataSets(new DataSet().setId("dataSet").setDataProvider(chartData).setColor(Color.valueOf("#b0de09")).setCategoryField("date").addFieldMappings(new FieldMapping().setFromField("value").setToField("value"), new FieldMapping().setFromField("volume").setToField("volume"))).addPanels(new StockPanel().setId("p1").setTitle("Value").setPercentHeight(70).setShowCategoryAxis(false).addStockGraphs(new StockGraph().setId("sg4").setValueField("value").setLineThickness(2).setType(GraphType.SMOOTHED_LINE).setBullet(BulletType.ROUND)).setStockLegend(new StockLegend().setValueTextRegular(" ").setMarkerType(MarkerType.NONE)), new StockPanel().setId("p2").setTitle("Volume").setPercentHeight(30).addStockGraphs(new StockGraph().setValueField("volume").setCornerRadiusTop(2).setType(GraphType.COLUMN).setFillAlphas(1.0)).setStockLegend(new StockLegend().setValueTextRegular(" ").setMarkerType(MarkerType.NONE))).setChartScrollbarSettings(new ChartScrollbarSettings().setGraph("sg4").setUsePeriod("10mm").setPosition(ChartScrollbarPosition.TOP)).setChartCursorSettings(new ChartCursorSettings().setValueLineBalloonEnabled(true)).setPeriodSelector(new PeriodSelector().setPosition(Position.TOP).setInputFieldWidth(150).addPeriods(new Period().setPeriod(PeriodType.HOURS).setCount(1).setLabel("1 hour").setSelected(true), new Period().setPeriod(PeriodType.HOURS).setCount(2).setLabel("2 hours"), new Period().setPeriod(PeriodType.HOURS).setCount(5).setLabel("5 hours"), new Period().setPeriod(PeriodType.HOURS).setCount(12).setLabel("12 hours"), new Period().setPeriod(PeriodType.MAX).setLabel("MAX"))).setPanelsSettings(new PanelsSettings().setUsePrefixes(true)).setExport(new Export().setPosition(ExportPosition.BOTTOM_RIGHT));
    StockChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(stockChart);
    String expected = readFile("StockChartWithIntradayDatas.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) DataSet(io.jmix.charts.model.dataset.DataSet) StockPanel(io.jmix.charts.model.chart.impl.StockPanel) FieldMapping(io.jmix.charts.model.dataset.FieldMapping) PanelsSettings(io.jmix.charts.model.settings.PanelsSettings) StockGraph(io.jmix.charts.model.stock.StockGraph) Period(io.jmix.charts.model.period.Period) ChartScrollbarSettings(io.jmix.charts.model.settings.ChartScrollbarSettings) StockChartSerializer(io.jmix.charts.widget.amcharts.serialization.StockChartSerializer) JmixStockChartSerializer(io.jmix.charts.serialization.JmixStockChartSerializer) CategoryAxesSettings(io.jmix.charts.model.axis.CategoryAxesSettings) Export(io.jmix.charts.model.export.Export) ChartCursorSettings(io.jmix.charts.model.settings.ChartCursorSettings) StockLegend(io.jmix.charts.model.stock.StockLegend) StockChartGroup(io.jmix.charts.model.chart.impl.StockChartGroup) PeriodSelector(io.jmix.charts.model.period.PeriodSelector) Test(org.junit.jupiter.api.Test)

Example 15 with ListDataProvider

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

the class StockChartSerializationTest method testStockChartWithMultipleDataSets.

@Test
public void testStockChartWithMultipleDataSets() throws ParseException, IOException, URISyntaxException {
    ListDataProvider chartData1 = new ListDataProvider();
    populateDataProvider(chartData1, 40L, 100L, 1000L, 500L, 2L);
    ListDataProvider chartData2 = new ListDataProvider();
    populateDataProvider(chartData2, 100L, 200L, 1000L, 600L, 2L);
    ListDataProvider chartData3 = new ListDataProvider();
    populateDataProvider(chartData3, 100L, 200L, 1000L, 600L, 2L);
    ListDataProvider chartData4 = new ListDataProvider();
    populateDataProvider(chartData4, 100L, 200L, 100L, 600L, 1L);
    StockChartGroup stockChart = new StockChartGroup().addDataSets(new DataSet().setId("dataSet1").setTitle("first data set").setDataProvider(chartData1).setCategoryField("date").addFieldMappings(new FieldMapping().setFromField("value").setToField("value"), new FieldMapping().setFromField("volume").setToField("volume")), new DataSet().setId("dataSet2").setTitle("second data set").setDataProvider(chartData2).setCategoryField("date").addFieldMappings(new FieldMapping().setFromField("value").setToField("value"), new FieldMapping().setFromField("volume").setToField("volume")), new DataSet().setId("dataSet3").setTitle("third data set").setDataProvider(chartData3).setCategoryField("date").addFieldMappings(new FieldMapping().setFromField("value").setToField("value"), new FieldMapping().setFromField("volume").setToField("volume")), new DataSet().setId("dataSet4").setTitle("forth data set").setDataProvider(chartData4).setCategoryField("date").addFieldMappings(new FieldMapping().setFromField("value").setToField("value"), new FieldMapping().setFromField("volume").setToField("volume"))).addPanels(new StockPanel().setId("panel1").setShowCategoryAxis(false).setTitle("Value").setPercentHeight(70).addStockGraphs(new StockGraph().setId("sg1").setValueField("value").setComparable(true).setCompareField("value").setBalloonText("[[title]]:&lt;b&gt;[[value]]&lt;/b&gt;").setCompareGraphBalloonText("[[title]]:&lt;b&gt;[[value]]&lt;/b&gt;")).setStockLegend(new StockLegend().setPeriodValueTextComparing("[[percents.value.close]]%").setPeriodValueTextRegular("[[value.close]]")), new StockPanel().setId("panel2").setTitle("Volume").setPercentHeight(30).addStockGraphs(new StockGraph().setValueField("volume").setType(GraphType.COLUMN).setShowBalloon(false).setFillAlphas(1.0)).setStockLegend(new StockLegend().setPeriodValueTextRegular("[[value.close]]"))).setChartScrollbarSettings(new ChartScrollbarSettings().setGraph("sg1")).setChartCursorSettings(new ChartCursorSettings().setValueBalloonsEnabled(true).setValueLineAlpha(0.5).setCursorAlpha(0.1).setValueBalloonsEnabled(true).setValueLineEnabled(true).setFullWidth(true)).setPeriodSelector(new PeriodSelector().addPeriods(new Period().setPeriod(PeriodType.MONTHS).setSelected(true).setCount(1).setLabel("1 month"), new Period().setPeriod(PeriodType.YEARS).setCount(1).setLabel("1 year"), new Period().setPeriod(PeriodType.YTD).setLabel("YTD"), new Period().setPeriod(PeriodType.MAX).setLabel("MAX"))).setDataSetSelector(new DataSetSelector().setPosition(Position.LEFT)).setExport(new Export());
    StockChartSerializer serializer = getTestSerializer();
    String json = serializer.serialize(stockChart);
    String expected = readFile("StockChartWithMultipleDataSets.json");
    assertEquals(prettyJson(expected), prettyJson(json));
}
Also used : ListDataProvider(io.jmix.ui.data.impl.ListDataProvider) DataSet(io.jmix.charts.model.dataset.DataSet) StockPanel(io.jmix.charts.model.chart.impl.StockPanel) FieldMapping(io.jmix.charts.model.dataset.FieldMapping) StockGraph(io.jmix.charts.model.stock.StockGraph) Period(io.jmix.charts.model.period.Period) ChartScrollbarSettings(io.jmix.charts.model.settings.ChartScrollbarSettings) DataSetSelector(io.jmix.charts.model.dataset.DataSetSelector) StockChartSerializer(io.jmix.charts.widget.amcharts.serialization.StockChartSerializer) JmixStockChartSerializer(io.jmix.charts.serialization.JmixStockChartSerializer) Export(io.jmix.charts.model.export.Export) ChartCursorSettings(io.jmix.charts.model.settings.ChartCursorSettings) StockLegend(io.jmix.charts.model.stock.StockLegend) StockChartGroup(io.jmix.charts.model.chart.impl.StockChartGroup) PeriodSelector(io.jmix.charts.model.period.PeriodSelector) 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