Search in sources :

Example 11 with Container

use of com.vaadin.v7.data.Container in project charts by vaadin.

the class ChartWithExternalContainer method createContainerView1.

private ContainerDataSeries createContainerView1(Container vaadinContainer) {
    ContainerDataSeries container = new ContainerDataSeries(vaadinContainer);
    container.setName("Order item quantities");
    container.setPlotOptions(new PlotOptionsPie());
    container.setYPropertyId(ExampleUtil.ORDER_QUANTITY_PROPERTY_ID);
    container.setNamePropertyId(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID);
    return container;
}
Also used : PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie) ContainerDataSeries(com.vaadin.v7.addon.charts.model.ContainerDataSeries)

Example 12 with Container

use of com.vaadin.v7.data.Container in project charts by vaadin.

the class ContainerWithLotsOfData method createContainer.

@SuppressWarnings("unchecked")
private ContainerDataSeries createContainer() {
    IndexedContainer vaadinContainer = new IndexedContainer();
    ContainerDataSeries container = new ContainerDataSeries(vaadinContainer);
    vaadinContainer.addContainerProperty("y", Number.class, null);
    for (int i = 0; i < getContainerData().length; i++) {
        Item item = vaadinContainer.addItem(i);
        item.getItemProperty("y").setValue(getContainerData()[i]);
    }
    container.setName("USD to EUR");
    container.setPlotOptions(new PlotOptionsArea());
    container.setYPropertyId("y");
    return container;
}
Also used : Item(com.vaadin.v7.data.Item) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) ContainerDataSeries(com.vaadin.v7.addon.charts.model.ContainerDataSeries)

Example 13 with Container

use of com.vaadin.v7.data.Container in project charts by vaadin.

the class ContainerWithLotsOfData method createTable.

private Component createTable(Container container) {
    Table t = new Table();
    t.setCaption("Data from Vaadin Container");
    t.setContainerDataSource(container);
    t.setItemCaptionMode(ItemCaptionMode.ID);
    t.setImmediate(true);
    return t;
}
Also used : Table(com.vaadin.v7.ui.Table)

Example 14 with Container

use of com.vaadin.v7.data.Container in project charts by vaadin.

the class SimpleSparklineExample method getChart.

@Override
protected Component getChart() {
    Container container = new BeanItemContainer<StockData>(StockData.class, getStockData());
    Table table = new Table();
    table.setContainerDataSource(container);
    table.addGeneratedColumn("values", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            return new Sparkline(100, 20, (Number[]) source.getItem(itemId).getItemProperty(columnId).getValue());
        }
    });
    table.setVisibleColumns("month", "values", "latest");
    table.setHeightUndefined();
    return table;
}
Also used : BeanItemContainer(com.vaadin.v7.data.util.BeanItemContainer) Container(com.vaadin.v7.data.Container) Table(com.vaadin.v7.ui.Table) BeanItemContainer(com.vaadin.v7.data.util.BeanItemContainer) Sparkline(com.vaadin.addon.charts.Sparkline)

Example 15 with Container

use of com.vaadin.v7.data.Container in project charts by vaadin.

the class ContainerDataSeriesBeanSerializer method createDataArray.

private ArrayNode createDataArray(Container container, Map<String, Object> pidMap) {
    ArrayNode data = JsonNodeFactory.instance.arrayNode();
    Mode mode = null;
    for (Object o : pidMap.keySet()) {
        if (!(o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1) || o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2))) {
            mode = Mode.OBJECT;
            break;
        }
    }
    Object xProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1);
    if (xProperty == null) {
        xProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1;
    }
    Object yProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2);
    if (yProperty == null) {
        yProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2;
    }
    checkRequiredProperties(container, pidMap, yProperty);
    if (mode != Mode.OBJECT) {
        if (container.getContainerPropertyIds().contains(xProperty)) {
            mode = Mode.XY;
        } else {
            mode = Mode.ONLY_Y;
        }
    }
    for (Object iid : container.getItemIds()) {
        Item item = container.getItem(iid);
        switch(mode) {
            case ONLY_Y:
                addValue(data, item.getItemProperty(yProperty));
                break;
            case XY:
                Property itemPropertyX = item.getItemProperty(xProperty);
                Property itemPropertyY = item.getItemProperty(yProperty);
                if (itemPropertyX.getValue() != null && itemPropertyY.getValue() != null) {
                    ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
                    data.add(entryArray);
                    addValue(entryArray, itemPropertyX);
                    addValue(entryArray, itemPropertyY);
                } else {
                    data.addNull();
                }
                break;
            default:
                // render as json object
                ObjectNode entryObject = JsonNodeFactory.instance.objectNode();
                Property<?> x = item.getItemProperty(xProperty);
                if (x != null) {
                    addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1, x);
                }
                Property<?> y = item.getItemProperty(yProperty);
                if (y != null) {
                    addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2, y);
                }
                Iterator<String> iter = pidMap.keySet().iterator();
                while (iter.hasNext()) {
                    String name = iter.next();
                    Object id = pidMap.get(name);
                    if (!id.equals(xProperty) && !id.equals(yProperty)) {
                        addNamedValue(entryObject, name, item.getItemProperty(id));
                    }
                }
                data.add(entryObject);
                break;
        }
    }
    return data;
}
Also used : Item(com.vaadin.v7.data.Item) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Property(com.vaadin.v7.data.Property)

Aggregations

ContainerDataSeries (com.vaadin.v7.addon.charts.model.ContainerDataSeries)5 Table (com.vaadin.v7.ui.Table)5 Item (com.vaadin.v7.data.Item)4 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 Container (com.vaadin.v7.data.Container)3 IndexedContainer (com.vaadin.v7.data.util.IndexedContainer)3 Sparkline (com.vaadin.addon.charts.Sparkline)2 ExternalResource (com.vaadin.server.ExternalResource)2 Component (com.vaadin.ui.Component)2 Label (com.vaadin.ui.Label)2 Link (com.vaadin.ui.Link)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 Property (com.vaadin.v7.data.Property)2 BeanItemContainer (com.vaadin.v7.data.util.BeanItemContainer)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AbstractVaadinChartExample (com.vaadin.addon.charts.examples.AbstractVaadinChartExample)1 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)1 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)1 PlotOptionsPie (com.vaadin.addon.charts.model.PlotOptionsPie)1