How to use kendo chart data in Tooltip Template?
Asked Answered
C

1

6

I'm relatively new in kendo chart. I have a chart as following;

@(Html.Kendo().Chart<PlodWareWeb.Models.TotalDrilledBySize>()
    .Name("totalDrilledBySizeChart")
    .Title("Total Drilled By Size")

    .ChartArea(chartArea => chartArea.Background("transparent").Height(350))
    .DataSource(dataSource => dataSource.Read(read => read.Action("GetTotalDrilledBySizeChartData", "Home")))
    .Legend(legend => legend.Visible(false))
    .Series(series =>
    {
        series.Column(model => model.TotalDrilled, model => model.GroupName);
    })
    .CategoryAxis(axis => axis.Categories(model => model.HoleSize).Line(line => line.Visible(true)).Labels(labels => labels.Rotation(0)))
    .CategoryAxis(axis => axis.Categories(model => model.DisplayName)
    .Line(line => line.Visible(false))
    .Labels(labels => labels.Rotation(-90).Format("{0}")))
    .ValueAxis(axis => axis.Numeric().Labels(labels => labels.Format("{0}")))

    .Tooltip(tooltip => tooltip.Visible(true).Format("{0}%").Template("#= series.name #: #= value #")
    )
)

How can I show "model.DisplayName" and "model.HoleSize" as a Tooltip in Template? I've tried the following but it gives me "undefined". Can anyone help? Thank you.

.Template("#= model.DisplayName #: #= series.name #: #= value #")

or

.Template("#= CategoryAxis.model.DisplayName #: #= series.name #: #= value #")
Complicate answered 13/2, 2015 at 2:29 Comment(0)
P
9

To access the data of the chart you need to use "dataItem" as follows;

.Tooltip(tooltip => tooltip.Visible(true).Format("{0}%").Template("#= dataItem.DisplayName # #= dataItem.HoleSize #: #= series.name #: #= value #")

Hope this helps.

Presentation answered 13/2, 2015 at 2:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.