-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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; } }
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.
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
Asked: 2014-03-19 17:49:33 +0800
Seen: 25 times
Last updated: Mar 28 '14