Search in sources :

Example 1 with DataSetSelector

use of io.jmix.charts.model.dataset.DataSetSelector in project jmix by jmix-framework.

the class StockChartLoader method loadDataSetSelector.

protected void loadDataSetSelector(StockChart chart, Element element) {
    Element dataSetSelectorElement = element.element("dataSetSelector");
    if (dataSetSelectorElement != null) {
        DataSetSelector dataSetSelector = new DataSetSelector();
        String comboBoxSelectText = dataSetSelectorElement.attributeValue("comboBoxSelectText");
        if (StringUtils.isNotEmpty(comboBoxSelectText)) {
            dataSetSelector.setComboBoxSelectText(comboBoxSelectText);
        }
        String compareText = dataSetSelectorElement.attributeValue("compareText");
        if (StringUtils.isNotEmpty(compareText)) {
            dataSetSelector.setCompareText(compareText);
        }
        String listHeight = dataSetSelectorElement.attributeValue("listHeight");
        if (StringUtils.isNotEmpty(listHeight)) {
            dataSetSelector.setListHeight(Integer.valueOf(listHeight));
        }
        String position = dataSetSelectorElement.attributeValue("position");
        if (StringUtils.isNotEmpty(position)) {
            dataSetSelector.setPosition(Position.valueOf(position));
        }
        String selectText = dataSetSelectorElement.attributeValue("selectText");
        if (StringUtils.isNotEmpty(selectText)) {
            dataSetSelector.setSelectText(selectText);
        }
        String width = dataSetSelectorElement.attributeValue("width");
        if (StringUtils.isNotEmpty(width)) {
            dataSetSelector.setWidth(Integer.valueOf(width));
        }
        chart.setDataSetSelector(dataSetSelector);
    }
}
Also used : DataSetSelector(io.jmix.charts.model.dataset.DataSetSelector) Element(org.dom4j.Element)

Example 2 with DataSetSelector

use of io.jmix.charts.model.dataset.DataSetSelector 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]]:<b>[[value]]</b>").setCompareGraphBalloonText("[[title]]:<b>[[value]]</b>")).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

DataSetSelector (io.jmix.charts.model.dataset.DataSetSelector)2 StockChartGroup (io.jmix.charts.model.chart.impl.StockChartGroup)1 StockPanel (io.jmix.charts.model.chart.impl.StockPanel)1 DataSet (io.jmix.charts.model.dataset.DataSet)1 FieldMapping (io.jmix.charts.model.dataset.FieldMapping)1 Export (io.jmix.charts.model.export.Export)1 Period (io.jmix.charts.model.period.Period)1 PeriodSelector (io.jmix.charts.model.period.PeriodSelector)1 ChartCursorSettings (io.jmix.charts.model.settings.ChartCursorSettings)1 ChartScrollbarSettings (io.jmix.charts.model.settings.ChartScrollbarSettings)1 StockGraph (io.jmix.charts.model.stock.StockGraph)1 StockLegend (io.jmix.charts.model.stock.StockLegend)1 JmixStockChartSerializer (io.jmix.charts.serialization.JmixStockChartSerializer)1 StockChartSerializer (io.jmix.charts.widget.amcharts.serialization.StockChartSerializer)1 ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)1 Element (org.dom4j.Element)1 Test (org.junit.jupiter.api.Test)1