0

ZK Charts -Model Duplicate values on spline,pie

asked 2014-03-19 17:49:33 +0800

neels gravatar image neels
0

I'm receiving duplicated values in the charts. the initial init the chart is ok, but on subsequent requests the data get duplicated. i.e values on x-axis will be Q1 Q2 Q3 and then 3 4 5

ZUL: <window apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') @init('SingleValueCategoryModelVM')"> <charts id="splineChart" type="spline" model="@bind(vm.model)" title="" width="600" height="600"/> <datebox id="dBox" format="yyyy-MM-dd" value="@bind(vm.date)"/> </window>

SingleValueCategoryModelVM:: NotifyChange("model") public void setDate(java.util.Date theDate) { this.date = theDate; model = SingleValueCategoryModelData.getModel(); }

SingleValueCategoryModelData: public class SingleValueCategoryModelData { public static CategoryModel getModel() { int year = 2014; CategoryModel model = new SimpleCategoryModel(); model.setValue(year - 1 + "", "Q1", new Integer(20)); model.setValue(year - 1 + "", "Q2", new Integer(35)); model.setValue(year - 1 + "", "Q3", new Integer(40)); return model; } }

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2014-03-20 03:23:23 +0800

RaymondChao gravatar image RaymondChao
386 1 4
ZK Team

Hi,

It seems the data get duplicated. If you want to change the chart's series when the year changed by datebox. The current workaround is to determine whether the model need to reset or not. For example:

@NotifyChange("model")
public void setDate(Date date) {
    // if the selected year equals to the model series, do not need to reset model
    if (this.date.getYear() != date.getYear()) {
        this.date = date;
        model = TestData.getModel(date);
    }
}

The sample code is as below:

test.zul

<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('TestVM')">
    <charts id="splineChart" type="spline" model="@bind(vm.model)" title="" width="600" height="600"/>
     <datebox id="dBox" format="yyyy-MM-dd" value="@bind(vm.date)"/>
</window>

TestVM.java

public class TestVM {
    private Date date;
    CategoryModel model;

    @Init
    public void init() {
        date = new Date();
        model = TestData.getModel(date);
    }

    @NotifyChange("model")
    public void setDate(Date date) {
        if (this.date.getYear() != date.getYear()) {
            this.date = date;
            model = TestData.getModel(date);
        }
    }

    public Date getDate() {
        return date;
    }

    public CategoryModel getModel() {
        return model;
    }
}

TestData.java

public class TestData {
    public static CategoryModel getModel(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int year = calendar.get(Calendar.YEAR);
        CategoryModel model = new SimpleCategoryModel();
        model.setValue(year - 1 + "", "Q1", new Integer(20));
        model.setValue(year - 1 + "", "Q2", new Integer(35));
        model.setValue(year - 1 + "", "Q3", new Integer(40));
        return model;
    }
}

Please let me know if you have any questions or concerns.

link publish delete flag offensive edit

answered 2014-03-28 08:57:37 +0800

neels gravatar image neels
0
Hi

Was wondering why i could not get something like this to work as an alternative.

for (int i = 0; i < chart1.getSeriesSize(); i++) {
System.out.println(" -- " + i  + " " + chart1.getSeries(i).getName());
chart1.getSeries(i).remove();
}

//and then redraw...
        chart1.setTheme(org.zkoss.chart.Theme.GRID);
    enter code here
        chart1.getXAxis().setTitle("");
..
..
chart1.setModel(model);

thanks,cheers Neels

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-03-19 17:49:33 +0800

Seen: 25 times

Last updated: Mar 28 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More