New to Kendo UI for jQuery? Start a free 30-day trial

Legend.item

configuration

The configuration of the Chart legend item.

To override the marker configuration of individual series, use the series.legendItem settings of the series.

<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",
      markers: {
        visible: true
      },
      field: "Close"
  }],
  legend: {
    visible: true,
    position: 'bottom',
    item: {
      highlight: {
        visible: false
      }
    }
  }
});
</script>
<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: "candlestick",
    openField: "Open",
    highField: "High",
    lowField: "Low",
    closeField: "Close"
  }],
  legend: {
    visible: true,
    position: 'bottom'
  },
  seriesDefaults: {
      /* Use these settings to emulate the legacy legend item rendering */
      legendItem: {
          type: 'line',
          line: {
              dashType: 'solid',
          },
          markers: {
              visible: false
          },
          highlight: {
              visible: false
          }
      }
  }
});
</script>

Sets the configuration of the legend items of type area. By default, all series except line and scatter use this legend type.

<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: "candlestick",
    openField: "Open",
    highField: "High",
    lowField: "Low",
    closeField: "Close"
  }],
  legend: {
    visible: true,
    position: 'bottom',
    item: {
      area: {
        opacity: 0.1,
      }
    }
  }
});
</script>

The cursor style of the legend item.

<div id="stock-chart"></div>
<script>
$("#stock-chart").kendoStockChart({
    dataSource: {
        data: [
            { date: new Date(2023, 0, 1), value: 100 },
            { date: new Date(2023, 0, 2), value: 105 },
            { date: new Date(2023, 0, 3), value: 98 }
        ]
    },
    legend: {
        item: {
            cursor: "pointer"
        }
    },
    series: [{
        field: "value",
        categoryField: "date",
        name: "Stock Price"
    }]
});
</script>

The highlight configuration of the legend item.

<div id="stock-chart"></div>
<script>
$("#stock-chart").kendoStockChart({
    dataSource: {
        data: [
            { date: new Date(2023, 0, 1), value: 100 },
            { date: new Date(2023, 0, 2), value: 105 },
            { date: new Date(2023, 0, 3), value: 98 }
        ]
    },
    legend: {
        item: {
            highlight: {
                markers: {
                    background: "yellow"
                },
                visible: true
            }
        }
    },
    series: [{
        field: "value",
        categoryField: "date",
        name: "Stock Price"
    }]
});
</script>

Sets the configuration of the legend items of type line. This is the default legend item type for all line and scatter series.

<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: "candlestick",
    openField: "Open",
    highField: "High",
    lowField: "Low",
    closeField: "Close"
  }],
  legend: {
    visible: true,
    position: 'bottom',
    item: {
      line: {
        color: "#777",
      }
    }
  }
});
</script>

The configuration of the Chart legend item markers.

By default, the marker configuration will be the same as the series.markers settings of the displayed series.

<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",
    markers: {
        visible: true
    },
    field: "Close"
  }],
  legend: {
    visible: true,
    position: 'bottom',
    item: {
      markers: {
        visible: false
      }
    }
  }
});
</script>

Sets the type of the legend items. The default value is based on the series type.

The supported values are:

  • "line"—the legend items are rendered as a line. This is the default value for line charts.
  • "area"—the legend items are rendered as a filled rectangle. This is the default value for area charts.
<div id="stock-chart"></div>
<script>
$("#stock-chart").kendoStockChart({
    legend: {
        item: {
            type: "area"
        }
    },
    series: [{
        type: "line",
        data: [
            { date: new Date(2023, 0, 1), value: 10 },
            { date: new Date(2023, 0, 2), value: 25 },
            { date: new Date(2023, 0, 3), value: 15 }             
        ],
    }]
});
</script>

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 that can be used to get the default visual.
<div id="chart"></div>
<script>
    $("#chart").kendoStockChart({
        legend: {
            visible: true,
            position: "bottom",
            item: {
                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;
                }
            }
        },
        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: "candlestick",
            openField: "Open",
            highField: "High",
            lowField: "Low",
            closeField: "Close"
        }]
    });
</script>