DHTMLX Docs & Samples Explorer

Templates

It's possible to use a template instead of a fixed value. You may use a string or a function as a template.

A string as a template

In this case the defined string is used as a value, but the name of a data property is replaced with the corresponding value. The property name is contained in the ##:

var chart =  new dhtmlXChart({
     view:"bar",
     container:"chart_container",
     value:"#sales#",
     label:"#sales# %"
}

A function as a template

This approach is used when we need to define some rules for displayed value or modify this value. The function gets data object as a parameter and returns the displayed value.

var chart =  new dhtmlXChart({
    view:"bar",
    container:"chart_container",
    value:"#sales#",
    label:"#year#",
    color:function(obj){
        if (obj.sales > 5) return "#ff9900";
        else return "#66cc00";
    }
})