This is a migrated thread and some comments may be shown as answers.

Setting custom template on column chart results in NullReferenceException on template fields

6 Answers 107 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 15 Feb 2012, 01:12 PM
Hi!

KendoUI is fantastic, however one problem. I am trying to set a custom template on a column chart for its tooltip, however it seems to be unable to find the fields specified.

Datasource:
var usageData = @Html.Raw(@ServiceStack.Text.JsonSerializer.SerializeToString(Model.ParkingStats));

Code:
$('#chart-utilization').kendoChart({ 
    title: {
        text: "Parking utilization for week"
    },
    dataSource:{
        data: usageData[0].Usage
    },
    series:[{
        type: "column",
        field: "Max",
        name: "Max utilization"
    }],
    categoryAxis:{
        field: "Week"
    },
    tooltip: {
        visible: true,
        template: "${ Max } of ${ Capacity }"
    },
    legend: {
        visible: false
    }
});

The 'Max' and when changed 'Capacity' renders correct columns. But the template can't find either fields and throws a NullReferenceException.


Thanks in advance for your pro-tips ;-) !

Finest regards.

6 Answers, 1 is accepted

Sort by
0
Dennis
Top achievements
Rank 1
answered on 15 Feb 2012, 03:07 PM
0
Accepted
Alexander Valchev
Telerik team
answered on 15 Feb 2012, 03:32 PM
Hello Dennis,

Tooltip templates work with predefined variables. More information and example can be found in corresponding documentation.
In your case, try to change the template property to:
template: "#= value # of #= category #"

I hope this will solve your problem.


Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dennis
Top achievements
Rank 1
answered on 15 Feb 2012, 03:38 PM
Thanks again!
     template: "${value} of ${dataItem.Capacity}"
Works, is there a reason for using #= value # ? Just for reference and other people, the working JSFiddle: http://jsfiddle.net/3fW95/6/ 
ps. After all your help today, I am confident about the support you guys deliver and will buy a license directly after finishing this post!
0
Alexander Valchev
Telerik team
answered on 15 Feb 2012, 05:33 PM
Hi Dennis,

Thank you for the nice words.

You could use whichever syntax you prefer. In the newest version of the framework we introduced #: # for conformance with #= #. ${} was kept for compatibility, but both of them do the same job.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dennis
Top achievements
Rank 1
answered on 15 Feb 2012, 05:54 PM
Hi!

Any rational behind the newly introduced way? I'd like to use the best practise, but not sure if there is one.
0
Alexander Valchev
Telerik team
answered on 16 Feb 2012, 12:19 PM
Hi Dennis,

You should use the one that best fits to your requirements.
${} can be also used for HTML encoding in templates as shown in this examples.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Charts
Asked by
Dennis
Top achievements
Rank 1
Answers by
Dennis
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or