MVVM Pattern

From Documentation
Revision as of 03:24, 24 August 2018 by Hawk (talk | contribs) (Created page with "{{ZKChartsEssentialsPageHeader}} You still can work with Charts in MVVM pattern with some exceptional usage. = Get Charts = Get a <tt>Charts</tt> by <tt>wireComponents()</tt>,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


You still can work with Charts in MVVM pattern with some exceptional usage.

Get Charts

Get a Charts by wireComponents(), please refer to MVVM Reference / Wire Components

public class ShiftViewModel {
    @Wire
    Charts chart;

    //http://books.zkoss.org/zk-mvvm-book/8.0/advanced/wire_components.html
    @AfterCompose
    public void doAfterCompose(@ContextParam(ContextType.VIEW) Component view) throws Exception {
        Selectors.wireComponents(view, this, false);
        // initial series data
        initPoints();
        // hide some unnecessary options
        hideOptions();
    }
...

Get ChartsEvent

Because you usually need ChartsEvent API, you can get it by @ContextParam like:

    @Command
    public void shiftPoint(@ContextParam(ContextType.TRIGGER_EVENT) ChartsEvent event) {
        // retrieve the point object.
        Point point = event.getPoint();
        // shift the point by updating its x value.
        point.setX(point.getX().intValue() + random() / 10);
    }


< Get Complete Source Code of This Book >


Last Update : 2018/08/24

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.