Chart Model"

From Documentation
m (remove empty version history (via JWB))
 
(5 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
Here we describe how to implement a chart model (<javadoc type="interface">org.zkoss.zul.ChartModel</javadoc>). For the concept of component, model and render, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]].
 
Here we describe how to implement a chart model (<javadoc type="interface">org.zkoss.zul.ChartModel</javadoc>). For the concept of component, model and render, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]].
  
Depending on the type of the chart you want, you could implement one of <javadoc type="interface">org.zkoss.zul.PieModel</javadoc>, <javadoc type="interface">org.zkoss.zul.XYModel</javadoc>, <javadoc type="interface">org.zkoss.zul.GanttModel</javadoc>, <javadoc type="interface">org.zkoss.zul.HiLoModel</javadoc>, etc. In additions, there are the default implementations for them that you could use directly, such as <javadoc>org.zkoss.zul.SimplePieModel</javadoc>, <javadoc>org.zkoss.zul.SimpleXYModel</javadoc>, etc.
+
Depending on the type of chart you want, you could implement one of <javadoc type="interface">org.zkoss.zul.PieModel</javadoc>, <javadoc type="interface">org.zkoss.zul.XYModel</javadoc>, <javadoc type="interface">org.zkoss.zul.GanttModel</javadoc>, <javadoc type="interface">org.zkoss.zul.HiLoModel</javadoc>, etc. In addition, there are default implementations for them you could use directly, such as <javadoc>org.zkoss.zul.SimplePieModel</javadoc>, <javadoc>org.zkoss.zul.SimpleXYModel</javadoc>, etc.
  
 
For example, we could have a composer as follows.
 
For example, we could have a composer as follows.
  
 
<source lang="java">
 
<source lang="java">
public class ProgrammerModel implements Composer {
+
public class ProgrammerModelComposer extends SelectorComposer<Component> {
 
     public void doAfterCompose(Component comp) throws Exception {
 
     public void doAfterCompose(Component comp) throws Exception {
 
         PieModel piemodel = new SimplePieModel();
 
         PieModel piemodel = new SimplePieModel();
Line 15: Line 15:
 
         piemodel.setValue("VB", new Double(20.5));
 
         piemodel.setValue("VB", new Double(20.5));
 
         piemodel.setValue("PHP", new Double(15.5));
 
         piemodel.setValue("PHP", new Double(15.5));
         ((Chart)comp).setModel(piemodel);
+
         ((Chart) comp).setModel(piemodel);
 
     }
 
     }
 
}
 
}
Line 24: Line 24:
 
<source lang="xml">
 
<source lang="xml">
 
<chart title="Pie Chart" width="500" height="250" type="pie" threeD="false" fgAlpha="128"
 
<chart title="Pie Chart" width="500" height="250" type="pie" threeD="false" fgAlpha="128"
  apply="foo.ProgrammerModel"/>
+
  apply="foo.ProgrammerModelComposer"/>
 
</source>
 
</source>
  
=Version History=
+
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 04:38, 5 February 2024

Here we describe how to implement a chart model (ChartModel). For the concept of component, model and render, please refer to the Model-driven Display section.

Depending on the type of chart you want, you could implement one of PieModel, XYModel, GanttModel, HiLoModel, etc. In addition, there are default implementations for them you could use directly, such as SimplePieModel, SimpleXYModel, etc.

For example, we could have a composer as follows.

public class ProgrammerModelComposer extends SelectorComposer<Component> {
    public void doAfterCompose(Component comp) throws Exception {
        PieModel piemodel = new SimplePieModel();
        piemodel.setValue("C/C++", new Double(12.5));
        piemodel.setValue("Java", new Double(50.2));
        piemodel.setValue("VB", new Double(20.5));
        piemodel.setValue("PHP", new Double(15.5));
        ((Chart) comp).setModel(piemodel);
    }
}

Then, you could use it in a ZUML document:

<chart title="Pie Chart" width="500" height="250" type="pie" threeD="false" fgAlpha="128"
 apply="foo.ProgrammerModelComposer"/>




Last Update : 2024/02/05

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