From Documentation

Jump to: navigation, search




  • Author
    Leonardo Nigro, Engineer
  • Date
    October 01, 2011
  • Version
    1.0

Contents

Introduction

This article shows how to use ZKH5chart components in a ZK application.

ZKH5Chart (based on h5chart javascript library) is a set of components that are useful to create and compose graphics and data charts in ZK. The library includes a set of drawing tools and H5Chart elements that are canvas elements where the components are drawn in.

Base component

H5Chart

Is the canvas where the charts and tools are drawn in. In this component (H5Chart), you can add many graphic components, so, with that in mind, you can create rich and complex charts.

Every graphic component is positionable and dimensionable (left, top, width and height support) relative to the canvas drawing area. The starting position (0,0) is on the top left corner.


//To create the base component
H5Chart chart=new H5Chart();
chart.setWidth("300");
chart.setHeight("300");

chart.setRegionManager(true); //for tooltips on click

Tools

Rectangle

Draws a rectangle or a rounded corner rectangle in the chart. Can customize fill style (solid or gradient), fill color, border width, border color, border style (solid or dotted) and shadow.


Rectangle t=new Rectangle();
		
t.setLeft("10");
t.setTop("10");
t.setWidth("150");
t.setHeight("80");
		
t.setColor("green");
t.setFillStyle(Rectangle.FILL_VLINEAR);
t.setEndColor("white");
t.setBorderColor("red");
t.setBorderStyle(Rectangle.BORDER_SOLID);
t.setBorderWidth(1);
t.setShadow(true);
t.setRadius(10);

chart.appendChild(t);

Text

Draws a string in the canvas. Can customize font style, color and family, rotation and shadow.


Text t=new Text();
t.setLeft("0");
t.setTop("0");
t.setColor("green");
t.setShadow(true);
t.setFont("bold 20px Arial");
t.setText("Testing text");

chart.appendChild(t);

Line

Draws a line in the canvas. Can customize line width, color, orientation and shadow. Coordinates (x,y) must be less than (x1,y1)


Line t=new Line();
		
t.setLeft("10");
t.setTop("10");
t.setX1("150");
t.setY1("80");
		
t.setColor("green");
t.setBorderStyle(Line.BORDER_SOLID);
t.setBorderWidth(3);
t.setShadow(true);

chart.appendChild(t);

Circle Section

Draws a circle section in the canvas. Can customize color, border, fill style and shadow. Start angle is 0 degress (East) and rotation is clock wise.


CircleSection t=new CircleSection();
		
t.setLeft("0");
t.setTop("0");
		
t.setColor("green");
t.setFillStyle(CircleSection.FILL_CILINDER);
t.setEndColor("white");
t.setBorderStyle(CircleSection.BORDER_SOLID);
t.setBorderWidth(1);
t.setShadow(true);
t.setRadius(80);
t.setRadius1(30);
t.setStartAngle(0);
t.setEndAngle(360);

chart.appendChild(t);

Circle

Draws a circle in the canvas. Can customize color, border, fill style and shadow. Start angle is 0 degress (East) and rotation is clock wise.


Circle t=new Circle();
		
t.setLeft("0");
t.setTop("0");
		
t.setColor("green");
t.setFillStyle(Circle.FILL_SOLID);
t.setEndColor("white");
t.setBorderStyle(Circle.BORDER_SOLID);
t.setBorderWidth(1);
t.setShadow(true);
t.setRadius(80);

chart.appendChild(t);


Image

Draws an image in the canvas. Image sources can be url src or dom image element (passing id). Can resize the image setting distinct width and height


h5Image t=new h5Image();
t.setLeft("100");
t.setTop("0");
t.setWidth("150");
t.setHeight("50");
t.setSourceType(h5Image.SOURCE_SRC);
t.setSrc("../img/pie_ring.jpg");

chart.appendChild(t);

Charts

Are components that represents data in it. Mostly, they have parametrized objetive ranges and current data. At this moment only one dimension charts are implemented. Next release will include Multidimension charts (line, bars, areas, stacked, etc).

Digital

Numeric Digital Panel. Can customize every range color, animation (blink or not) animation counter , digits and decimal count. When current numeric data is within the range, the panel use the range definition and displays the data.

Digital.jpg


Digitalmeter t=new Digitalmeter();
t.setLeft("0");
t.setTop("0");
t.setWidth("120");
t.setHeight("50");
t.setCurrent(45);
t.setAnimate(true);
t.setDigits(3);
t.setDecimals(1);
t.setAnimateCounter(10);
t.setBackground(true);
t.setSigned(true);
		
t.addRange(10d, "#FA0000", "true");
t.addRange(20d, "#FAFA00", "true");
t.addRange(50d, "#00FA00", "false");

chart.appendChild(t);

Led

Led Matrix can display numeric and alphanumeric information in one row. Can customize every range color, message, animation (blink, Right to left movement or static) and animation counter. When current numeric data is within the range, the matrix displays the message whith the designed color and animation.

Led.jpg


Ledmeter t=new Ledmeter();
t.setLeft("0");
t.setTop("0");
t.setWidth("120");
t.setHeight("50");
t.setCurrent(45);
t.setAnimate(true);
t.setAnimateCounter(1);
				
t.addRange(10d, "#00FA00", Ledmeter.ANIMATE_NONE,"OK");
t.addRange(20d, "#8A8A00", Ledmeter.ANIMATE_BLINK,"WARNING");
t.addRange(50d, "#FA0000", Ledmeter.ANIMATE_RL,"ERROR");

chart.appendChild(t);

Signal

Multiple or individual signal light. Can customize every range color, animation (blink or static) and animation counter. When current numeric data is within the range, the signal is turned on with the designed color and animation.

Signal.jpg


Signal t=new Signal();
t.setLeft("0");
t.setTop("0");
t.setWidth("200");
t.setHeight("200");
t.setCurrent(45);
t.setAnimate(true);
t.setAnimateCounter(5);
t.setOrientation(Signal.HORIZONTAL);
		
t.addRange(10d, "#008000","true");
t.addRange(20d, "#808000","true");
t.addRange(100d, "#800000","true");

chart.appendChild(t);

Thermometer

Represents data in Thermometer way. Can customize range min and max.

Thermometer.jpg


Thermometer t=new Thermometer();
t.setLeft("0");
t.setTop("0");
t.setWidth("50");
t.setHeight("150");
t.setCurrent(45);
t.setAnimate(true);
t.setMax(50);
t.setMin(10);
t.setIntervals(5);

chart.appendChild(t);

Meter

Displays data in Ruler manner. If ranges are configured, the ruler is divided into customized ranges and current data is represented by rectangle. If ranges aren't present, current data is represented by a rectangle that fills the ruler. Can customize, colors, fonts and current data animation.

Meter.jpg


Meter t=new Meter();
t.setLeft("0");
t.setTop("0");
t.setBarSize(30);
t.setWidth("50");
t.setHeight("150");
t.setCurrent(45);
t.setAnimate(true);
						
t.addRange(10d, "#00FA00");
t.addRange(20d, "#8A8A00");
t.addRange(100d, "#FA0000");

chart.appendChild(t);

Radialmeter

Displays data in Radial Ruler manner. If ranges are configured, the ruler is divided into customized ranges and current data is represented by an arrow and arc (optional). If ranges aren't present, current data is represented by an arrow and arc (optional). Can customize, colors, fonts and current data animation (arrow and arc), ruler position and chart background style.

Radial.jpg


Radialmeter t=new Radialmeter();
t.setLeft("0");
t.setTop("0");
t.setWidth("200");
t.setHeight("200");
t.setCurrent(45);
t.setAnimate(true);
t.setCapacity(false);
t.setRulePosition(Radialmeter.RULE_POSITION_OUT);
		
t.addRange(10d, "#008000");
t.addRange(20d, "#808000");
t.addRange(100d, "#800000");

chart.appendChild(t);

Pie and Ring

Values and labels defined are represented in a pie or ring chart. Can customize clock wise or radial animation, colors, fonts, and visible values. Future release will include data mask customization. This chart does not include references. You can add them with the references component.

Pie ring1.jpg


//Pie

Pie t=new Pie();
t.setLeft("100");
t.setTop("0");
t.setWidth("200");
t.setHeight("200");
t.setAnimate(true);
t.setPizza(false);
t.setAnimateType(Pie.ANIMATION_RADIAL);
		
t.addValue(10d, "Value 1");
t.addValue(20d, "Value 2");
t.addValue(50d, "Valule 3");

chart.appendChild(t);

//Ring

Ring t1=new Ring();
t1.setLeft("100");
t1.setTop("0");
t1.setWidth("200");
t1.setHeight("200");
t1.setAnimate(true);
t1.setPizza(false);
t1.setAnimateType(Ring.ANIMATION_LINEAR);
		
t1.addValue(10d, "Value 1");
t1.addValue(20d, "Value 2");
t1.addValue(50d, "Valule 3");

chart.appendChild(t1);

References

Displays information in graph references format. The text can be displayed in rows or flow in natural way. Can customize the width (automatic height), flow (rows or natural), background, backcolor, border color and text color, font family and size.


References t=new References();
t.setLeft("0");
t.setTop("0");
t.setWidth("150");
t.setShadow(true);
t.setLabelFont("bold 12px Arial");
t.setLabelColor("grey");
t.setBackground(true);
t.setBackgroundColor("white");
t.setBorderColor("grey");
t.setShadow(true);

t.addRange("#008000","value 1");
t.addRange("#808000","value 2");
t.addRange("#800000","value 3");
t.setOrder("rows");

chart.appendChild(t);

Vumeter

Represents data in vumeter way filling the matrix with current data provided. Can customize limit ranges colors

Vumeter.jpg


Vumeter t=new Vumeter();
t.setLeft("0");
t.setTop("0");
t.setWidth("200");
t.setHeight("200");
t.setCurrent("10,15,50");
t.setXpoints(3);
t.setYpoints(10);
t.setAnimate(true);
t.setBackground(true);
t.setOrientation(Vumeter.VERTICAL);
		
t.addRange(10d, "#008000");
t.addRange(20d, "#808000");
t.addRange(100d, "#800000");

chart.appendChild(t);

Appendix



Copyright © Leonardo Nigro. This article is licensed under GNU Free Documentation License.
You got stuck here?
Let us know how we can improve this page
For specific questions please use the forum