seriesDefaults.legendItem.visual Function

A function that can be used to create a custom visual for the legend items. The available argument fields are:

  • options—The item options.
  • createVisual—A function for getting the default visual.
  • series—The item series.
  • pointIndex—The index of the point in the series. Available for the Pie, Donut, and Funnel series.

Example - using custom visual for the legend items

<div id="chart"></div>
<script>
$("#chart").kendoStockChart({
  dataSource: {
    data: [{
      "Date": "2016/01/01",
      "Open": 41.62,
      "High": 41.69,
      "Low": 39.81,
      "Close": 40.12,
      "Volume": 2632000
    }, {
      "Date": "2016/03/01",
      "Open": 40.62,
      "High": 39.69,
      "Low": 40.81,
      "Close": 39.12,
      "Volume": 2631986
    }]
  },
  dateField: "Date",
  series: [{
    name: "Series 1",
    type: "line",
    field: "Close",
    markers: {
      visible: true
    },
    legendItem: {
      visual: function (e) {
        var color = e.options.markers.background;
        var labelColor = e.options.labels.color;
        var rect = new kendo.geometry.Rect([0, 0], [100, 50]);
        var layout = new kendo.drawing.Layout(rect, {
          spacing: 5,
          alignItems: "center"
        });

        var marker = new kendo.drawing.Path({
          fill: {
            color: color
          }
        }).moveTo(10, 0).lineTo(15, 10).lineTo(5, 10).close();

        var label = new kendo.drawing.Text(e.series.name, [0, 0], {
          fill: {
            color: labelColor
          }
        });

        layout.append(marker, label);
        layout.reflow()

        return layout;
      }
    }
  }],
  legend: {
    visible: true,
    position: 'bottom'
  }
});
</script>
In this article