-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
I am following this demo http://www.zkoss.org/zkchartsdemo/pie_basic
I want to clear the chart (series) on a button click. Any help
I am little bit confused on different chart in ZK. What is zhighcharts as per this page
There are currently to bugs (ZKCHARTS-2, ZKCHARTS-3) open about model cleanup in ZK Charts. We need to wait until a fix is available. and replace the whole component instead of updating its model.
Robert
What do you mean by "replace the whole component instead of updating its model." How we can do that ?
Senthilchettyin ( 2014-04-10 05:20:58 +0800 )edit:). I need to rollback all and better to use any of the old chart like fusion chart in ZK. This is most complicated.
Senthilchettyin ( 2014-04-10 05:57:46 +0800 )editHi Hawk
I changed code to MVVM and still have the same problem. Second time, it does not clear the series, instead of that it is adding to the previous one.
Look at the Video Video Demo
Here is the ZUL Code
<charts id="chart" type="pie" model="@bind(vm.model)" title="Charges By Provider" />
VM
package com.product.webapp.charts;
import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.List;
import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.AfterCompose; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.ContextParam; import org.zkoss.bind.annotation.ContextType; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.chart.Charts; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zkplus.spring.SpringUtil; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.SimpleSingleValueCategoryModel; import org.zkoss.zul.SingleValueCategoryModel; import org.zkoss.zul.Textbox; import org.zkoss.zul.Window;
import com.product.business.customentity.BillingConditions; import com.product.business.service.BillingReportService; import com.product.domain.Location; import com.product.webapp.utilities.FHSessionUtil; import com.product.webapp.utilities.ShowWindow;
public class ChartProviderChargesVM {
@Wire("#chartprovidercharges")
private Window win;
@Wire("#chartmainlayout")
private Borderlayout borderLayout;
@Wire
private Charts chart;
@WireVariable
private BillingReportService billingReportService;
private List<SummaryData> dataList = new ArrayList<SummaryData>();
private BillingConditions billingCond = new BillingConditions();
private SummaryData selectedData;
private BigDecimal totalBilledAmount = BigDecimal.ZERO;
private Long totalClaims = 0L;
private SingleValueCategoryModel model;
public SingleValueCategoryModel getModel() {
return model;
}
public BillingConditions getBillingCond() {
return billingCond;
}
public void setBillingCond(BillingConditions billingCond) {
this.billingCond = billingCond;
}
public BigDecimal getTotalBilledAmount() {
return totalBilledAmount;
}
public void setTotalBilledAmount(BigDecimal totalBilledAmount) {
this.totalBilledAmount = totalBilledAmount;
}
public Long getTotalClaims() {
return totalClaims;
}
public void setTotalClaims(Long totalClaims) {
this.totalClaims = totalClaims;
}
public SummaryData getSelectedData() {
return selectedData;
}
public void setSelectedData(SummaryData selectedData) {
this.selectedData = selectedData;
}
public List<SummaryData> getDataList() {
return dataList;
}
public void setDataList(List<SummaryData> dataList) {
this.dataList = dataList;
}
@AfterCompose
public void initSetup(@ContextParam(ContextType.VIEW) Component view) {
Selectors.wireComponents(view, this, false);
billingReportService = (BillingReportService) SpringUtil
.getBean("BillingReportService");
billingCond.setPracticeID((long) 3);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
this.billingCond.setChargeSummaryType("visitProviderCode");
this.billingCond.setFromDOS(cal.getTime());
this.billingCond.setToDOS(new Date());
this.billingCond.setProviderType("B");
onApplyCondition();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Command
public void onApplyCondition() {
billingCond.setPracticeID(FHSessionUtil.getCurrentPractice().getID());
List<Object> results = billingReportService
.getChargesSummary(billingCond);
dataList = new ArrayList<SummaryData>();
this.totalBilledAmount = BigDecimal.ZERO;
this.totalClaims = 0L;
if (results.size() == 0) {
model = new SimpleSingleValueCategoryModel();
BindUtils.postNotifyChange(null, null, this, "*");
return;
}
model = new SimpleSingleValueCategoryModel();
for (Iterator it = results.iterator(); it.hasNext();) {
Object[] row = (Object[]) it.next();
dataList.add(new SummaryData((String) row[0], (Long) row[1],
(BigDecimal) row[2]));
model.setValue((String) row[0], (BigDecimal) row[2]);
totalBilledAmount = totalBilledAmount.add((BigDecimal) row[2]);
totalClaims = totalClaims + (Long) row[1];
}
BindUtils.postNotifyChange(null, null, this, "*");
}
@Command
public void OnLookUp(@BindingParam("type") String type) {
if (type.equalsIgnoreCase("Location"))
ShowWindow.showLocationLookup(win);
}
@Command
public void onFocusLookupValues(@BindingParam("target") Textbox target) {
target.select();
}
@Command
@NotifyChange("billingCond")
public void onSelectLocationLookup(
@BindingParam("selectedRecord") Location location) {
if (location != null)
this.billingCond.setLocationCode(location.getCode());
}
@Command
@NotifyChange("billingCond")
public void onClearLookupValues(@BindingParam("type") String type) {
if (type.equalsIgnoreCase("Location"))
this.billingCond.setLocationCode(null);
}
public class SummaryData {
private String data;
private Long count;
private BigDecimal billingAmount;
public SummaryData(String data, Long count, BigDecimal billingAmount) {
this.data = data;
this.count = count;
this.billingAmount = billingAmount;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public Long getCount() {
return count;
}
public void setCount(Long count) {
this.count = count;
}
public BigDecimal getBillingAmount() {
return billingAmount;
}
public void setBillingAmount(BigDecimal billingAmount) {
this.billingAmount = billingAmount;
}
}
}
Hi,
Series.remove()
will remove the series itself from charts component, so it doesn't work.
You can try to manipulate model (http://books.zkoss.org/wiki/ZKChartsEssentials/WorkingwithZKCharts/ManipulatingChart_Model) or add another new series to a charts component.
I try the below code, but no impact
@Command
public void onclear() {
chart.getChildren().clear();
chart.getSeries().remove();
chart.getSeries().clearOptonDataListener();
chart.getSeries().addPoint(new Point("asdasdasd", 10));
Messagebox.show("asdsadasdsad");
}
Asked: 2014-04-09 18:22:29 +0800
Seen: 109 times
Last updated: Jan 22 '16