Search code examples
javascriptkendo-uitelerikkendo-chart

How to make Kendo chart legend with circle icon?


I am seeing other answers but it's in triangle shape. What I really need is to do a circle icon like in the picture below:

Legend with circle icons

I tried customizing the "kendo.geometry.Rect" in this Dojo example by the Circle Geometry API. But I need help in understanding what I supposed to do.


Solution

  • You Circle Geometry only defines center and radius. You then need to use the drawing.Circle:

    visual: function (e) {
      // get color of current marker and label
      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"
      });
      // create a circle geometry centered at x=10, y=5, with a radius of 5
      var CircGeometry = new kendo.geometry.Circle([10, 5], 5);
      // draw the circle using the geometry and set the color (could have no stroke)
      var MarkerCircle = new kendo.drawing.Circle(CircGeometry, {
        stroke: { color: color, width: 1 },
        fill: { color: color }
      });
      //Create the text label
      var label = new kendo.drawing.Text(e.series.name, [0, 0], {
        fill: {
          color: labelColor
        }
      });
    
      //Add circle and label to layout object
      layout.append(MarkerCircle, label);
      layout.reflow()
    
      return layout;
    }