Search in sources :

Example 1 with TrendLine

use of io.jmix.charts.model.trendline.TrendLine in project jmix by jmix-framework.

the class ChartModelLoader method loadTrendLines.

protected void loadTrendLines(RectangularChartModel chart, Element element) {
    Element trendLinesElement = element.element("trendLines");
    if (trendLinesElement != null) {
        for (Object trendLineItem : trendLinesElement.elements("trendLine")) {
            Element trendLineElement = (Element) trendLineItem;
            TrendLine trendLine = new TrendLine();
            String balloonText = trendLineElement.attributeValue("balloonText");
            if (StringUtils.isNotEmpty(balloonText)) {
                trendLine.setBalloonText(balloonText);
            }
            String dashLength = trendLineElement.attributeValue("dashLength");
            if (StringUtils.isNotEmpty(dashLength)) {
                trendLine.setDashLength(Integer.valueOf(dashLength));
            }
            String finalCategory = trendLineElement.attributeValue("finalCategory");
            if (StringUtils.isNotEmpty(finalCategory)) {
                trendLine.setFinalCategory(finalCategory);
            }
            String finalDate = trendLineElement.attributeValue("finalDate");
            if (StringUtils.isNotEmpty(finalDate)) {
                trendLine.setFinalDate(loadDate(finalDate));
            }
            Element finalImageElement = trendLineElement.element("finalImage");
            if (finalImageElement != null) {
                trendLine.setFinalImage(loadImage(finalImageElement));
            }
            String finalValue = trendLineElement.attributeValue("finalValue");
            if (StringUtils.isNotEmpty(finalValue)) {
                trendLine.setFinalValue(Double.valueOf(finalValue));
            }
            String finalXValue = trendLineElement.attributeValue("finalXValue");
            if (StringUtils.isNotEmpty(finalXValue)) {
                trendLine.setFinalXValue(Double.valueOf(finalXValue));
            }
            String id = trendLineElement.attributeValue("id");
            if (StringUtils.isNotEmpty(id)) {
                trendLine.setId(id);
            }
            String initialCategory = trendLineElement.attributeValue("initialCategory");
            if (StringUtils.isNotEmpty(initialCategory)) {
                trendLine.setInitialCategory(initialCategory);
            }
            String initialDate = trendLineElement.attributeValue("initialDate");
            if (StringUtils.isNotEmpty(initialDate)) {
                trendLine.setInitialDate(loadDate(initialDate));
            }
            Element initialImageElement = trendLineElement.element("initialImage");
            if (initialImageElement != null) {
                trendLine.setFinalImage(loadImage(initialImageElement));
            }
            String initialValue = trendLineElement.attributeValue("initialValue");
            if (StringUtils.isNotEmpty(initialValue)) {
                trendLine.setInitialValue(Double.valueOf(initialValue));
            }
            String initialXValue = trendLineElement.attributeValue("initialXValue");
            if (StringUtils.isNotEmpty(initialXValue)) {
                trendLine.setInitialXValue(Double.valueOf(initialXValue));
            }
            String isProtected = trendLineElement.attributeValue("isProtected");
            if (StringUtils.isNotEmpty(isProtected)) {
                trendLine.setProtected(Boolean.valueOf(isProtected));
            }
            String lineAlpha = trendLineElement.attributeValue("lineAlpha");
            if (StringUtils.isNotEmpty(lineAlpha)) {
                trendLine.setLineAlpha(Double.valueOf(lineAlpha));
            }
            String lineColor = trendLineElement.attributeValue("lineColor");
            if (StringUtils.isNotEmpty(lineColor)) {
                trendLine.setLineColor(Color.valueOf(lineColor));
            }
            String lineThickness = trendLineElement.attributeValue("lineThickness");
            if (StringUtils.isNotEmpty(lineThickness)) {
                trendLine.setLineThickness(Integer.valueOf(lineThickness));
            }
            String valueAxis = trendLineElement.attributeValue("valueAxis");
            if (StringUtils.isNotEmpty(valueAxis)) {
                trendLine.setValueAxis(valueAxis);
            }
            String valueAxisX = trendLineElement.attributeValue("valueAxisX");
            if (StringUtils.isNotEmpty(valueAxisX)) {
                trendLine.setValueAxisX(valueAxisX);
            }
            chart.addTrendLines(trendLine);
        }
    }
}
Also used : Element(org.dom4j.Element) TrendLine(io.jmix.charts.model.trendline.TrendLine)

Example 2 with TrendLine

use of io.jmix.charts.model.trendline.TrendLine 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)

Aggregations

TrendLine (io.jmix.charts.model.trendline.TrendLine)2 Scrollbar (io.jmix.charts.model.Scrollbar)1 ValueAxis (io.jmix.charts.model.axis.ValueAxis)1 Cursor (io.jmix.charts.model.cursor.Cursor)1 Graph (io.jmix.charts.model.graph.Graph)1 ChartSerializer (io.jmix.charts.widget.amcharts.serialization.ChartSerializer)1 ListDataProvider (io.jmix.ui.data.impl.ListDataProvider)1 MapDataItem (io.jmix.ui.data.impl.MapDataItem)1 Element (org.dom4j.Element)1 Test (org.junit.jupiter.api.Test)1