whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
WHY ARTFULBITS
whitespace
OUR APPROACH
whitespace
OUR TEAM
whitespace
FACT SHEET
whitespace
NEWS & EVENTS
whitespace
PRIVACY
whitespace
whitespace

How to declare chart XML file in android

Contents

Introduction

aiCharts library offers an easy way to define chartпїЅs look and structure. It gives developer ability to define chart via XML file and reuse it in a very same way as default Android layout XML files. This is not mandatory to define parts of your chart UI in the XML, but we highly recommend it.

Configuring your Eclipse environment

Eclipse IDE is shipped with XML editor that you can use to view/edit chart XML declaration. In order to make editor correctly recognize chart structure, in eclipse go to Preferences > XML > XML catalog > Add and enter aiCharts.xsd schema location that is included in aiCharts SDK.

Declaring XML chart

In order to declare chartпїЅs structure, do following:

  • Describe chart in XML file (see XML structure below)
  • Add XML file into /res/xml/ project structure
  • In your layout, set the "chart" attribute of ChartView to @xml/<your_xml_file>

Target XML chart definition will be applied to ChartView upon layout inflation (in most cases, when Activity.setContentView() method is executed).
Consider following chart XML sample:

<?xml version="1.0" encoding="UTF-8"?>
<chart>
    <title text="Chart XML Sample"/>
    <area grid="@drawable/bk_grid">
        <area.xaxis position="Top"/>
    </area>
    <series type="Column" showlabel="true" points="20, 10, 40, 30, 50"/>
    <legend dock="Right"/>
</chart>
  

This XML defines chart containing title, background (referenced to application resources drawable bk_grid.png), column series and legend. Assigning this XML to ChartView will result following output:

Preview of Chart after configuration
Preview of Chart after configuration

XML file structure

Logical XML chart structure is expressed via areas, series, legends and titles. Every element can be specified in XML file with its corresponding attributes. If any of elements is not mentioned in chart XML declaration, it will be automatically created by chart building engine.

Overall XML chart structure:

<?xml version="1.0" encoding="UTF-8"?>
<chart>
    <area>
      <area.xaxis/>
      <area.yaxis/>
    <area/>
    <series/>
    <legend/>
    <title/>
</chart>
  

Please refer to description below for complete attributes supported by each element.

Area attributes

Area is child element of пїЅchartпїЅ. Following attributes are supported:

Name Type Description
grid Drawable resource id Defines drawable reference to image that aiCharts will use to render area's grid background.
background Drawable resource id Defines drawable reference to image that aiCharts will use to render area's background.
name String Defines area name.

X-Axis and Y-Axis attrbiutes

Both: the x-axis and y-axis elements are expected to be children of area element. Following attributes are supported:

Name Type Description
position ChartAxis.Position enum names Defines axis position. Used to change default position of axis.
visible Boolean Defines axis visibility. True by default.
labels_visible Boolean Defines labels visibility. True by default. Used to restrict axis from drawing itпїЅs labels.
labels_mode ChartAxis.LabelsMode enum names Defines labels generation mode.
title String Defines axis title name.
ticks_mode ChartAxis.TickMarkMode enum names Defines tick mode.
ticks_size Integer Defines tick size. Used to customize axis appearance.
format MessageFormat pattern Defines labels format. Used for custom labels scenarios.
spacing Integer Defines distance between axis elements.
padding Integer Defines distance between axis and area.
grid_linescolor Integer Defines grid lines color.
grid_visible Boolean Defines grid visibility. True by default. Used to restrict axis from drawing itпїЅs grid.
scale_min Double Defines minimal value of axis scale.
scale_max Double Defines maximal value of axis scale.
scale_interval Double Defines interval between labels.
scale_intervalType ChartAxisScale.IntervalType enum names Defines type of interval between labels.

Series attributes

Series is a chartпїЅs building block that takes care of data visualization. General purpose of setting series in XML is to define series immutable parts (color, type, width, etc). Allowed attributes:

Name Type Description
name String Defines series name. Legend uses this name to display series data. Generally, thereпїЅs no need to set this attribute if access series by name and legend is not required.
area String Defines area name. Tells series which area must use it. If this attribute not set, first area will use this series and draw it
legend String Defines legend name. This is typically used to allow several legends in a single area. Setting legend name, tells series which legend it belongs to.
type String Defines ChartType name.
points coma separated double array Defines Y values of points. For most cases, this attribute may be used for static data representation.
background Drawable resource id Defines background resource. This drawable can be assigned just as much as any other: @drawable/<resource_id>
filter Boolean Enables color filter for background drawable.
marker Drawable resource id Defines marker drawable resource.
markerSize One or two coma- separated integers пїЅx, yпїЅ Defines marker size.
showlabel Boolean Defines label visibility. Identifies whether labels belonging to this series should be visible.
color Integer color value Defines series color.
border Integer color value Defines series border color.
linewidth Integer Defines series border or line width. This attribute is treated differently depending on chart type.
halign Alignment enum names Defines series label horizontal position.
valign Alignment enum names Defines series label vertical position.

Legend attributes

Legend is an element above, below or somewhere near the chart area which explains what is represented by series.

Name Type Description
name String Defines legend name.
background Drawable resource id Defines background resource. This drawable can be assigned just as much as any other: @drawable/<resource_id>.
dock ChartLeyoutElement.Dock enum names Defines legend position.
visible Boolean Defines legend visibility.

Title attributes

Titles are used to make user more information about the chart, types of data, timeframes.

Name Type Description
image Drawable resource id Defines image resource.
text String Defines title text.
dock ChartLeyoutElement.Dock enum names Defines title position.
halign Alignment enum names Defines image horizontal position.
valign Alignment enum names Defines image vertical position.
visible Boolean Defines title visibility.

Conclusion

Android Chart Engine - aiCharts, is number one on Java charts market, designed and optimized for Android. It gives developer enormous advantage in compare to other Java charts engines which potentially can support Android. Native support of Android development environment, easy installation, complete set of tutorials and samples - all that makes integration with aiCharts simple and painless.

Having ability to define chartпїЅs look and feel via XML gives developers and designers freedom to express their ideas of how they like chart to be. ChartпїЅs UI and logic decoupling makes source application more readable and robust.

Please see samples included to aiCharts SDK for more ideas. Feel free to ask your questions in aiCharts support forum.

Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.