Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use kendo chart data in Tooltip Template?

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 #")
like image 686
Siddik Avatar asked Feb 13 '15 02:02

Siddik


1 Answers

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.

like image 91
Mahib Avatar answered Nov 02 '22 19:11

Mahib