Chart legend explains data and color correspondence. Generally, to specify the chart legend you should use the legend property:
Specifying the legend for a chart
webix.ui({
view:"chart",
type:"bar",
...
legend:{
values:[
{text:"Company A", color:"#58dccd"},
{text:"Company B", color:"#a7ee70"},
{text:"Company C", color:"#36abee"}
],
align:"right",
width:110,
layout:"y"
}
})
Related sample: Bar Chart: Several Graphs in One Chart
See the full list of legend parameters in API Reference.
Built-in means allow defining a default legend. For these needs, you should specify what element from the initial data source will be in the legend area. Default legend is great for pie and bar charts with multicolored bars and pie pieces.
Then, the legend takes a color value from the dataset:
JSON Data
[
{ sales:"20", month:"Jan", color: "#ee3639" },
{ sales:"30", month:"Fen", color: "#ee9e36" }
]
webix.ui({
view:"chart",
type:"pie",
value:"#sales#",
color:"#color#",
legend:"#month#"
});
Related sample: Pie Chart: Basic and Custom Legend
See the full list of legend parameters in API Reference.
Legend markers become "show-and-hide" buttons for all charts with series except for stacked charts (stackedArea, stackedBar, stackedBarH), because such charts presuppose series usage and don't imply visual comparison.
Custom legend
webix.ui({
view:"chart",
type:"radar",
legend:{
layout:"y",
width: 110,
align:"right",
valign:"middle",
marker:{
width:15,
radius:3
},
values:[
{text:"company A",color:"#3399ff"},
{text:"company B",color:"#66cc00"}]
}
});
Related sample: Radar Chart: Lines
See the full list of legend parameters in API Reference.
By default, legend markers are squares with rounded edges that feature 3-px border radius. To change this pattern, use the marker parameter of the into the legend property.
legend:{
...
marker:{
type:"round",
width:15,
radius:3
},
}
Related sample: Radar Chart: Areas
Webix charts offer a possibility to set for a marker the same template that uses items of the related graph.
legend:{
values:[{text:"Company A"},{text:"Company B"},{text:"Company C"}],
...
marker:{
type: "item",
width: 18
}
}
Related sample: Line Chart: Legend Markers
To set different markers for graphs you should:
legend:{
layout:"y",
align:"right",
valign:"middle",
width:100,
values:[
{text:"Company A",color:"#00ccff"}, //the default marker
{text:"Company B",color:"#e9df40"}, //the default marker
{text:"Average",color:"#b25151", markerType: "item"} //the redefined marker
]
}
Related sample: Bar Chart: Different Types in One Chart
Back to top