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

HELP ! String labels on both axes

2 Answers 137 Views
Charts
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 17 Jul 2012, 04:21 PM
I have a requirement for BOTH axes to show a string label. My problem is that I need the value axis to show a string label the way the category axis does by default. The column chart below renders the tooltips correctly when I use the: template: "#= dataItem.ProductName #". If I try to use the dataItem property in the LABELS template section, it's not there. I realize that the value axis must be numeric. That is fine. What I need is to replace the y-axis numeric value label with it's non-numeric label contained in the model. There simply must be a way to intercept that label and convert it to a string.  For example.. template : #= (value==3) ? 'string' : 'string' # . Or maybe an event, even an internal event. Do I have to examine the chart AFTER it is rendered and find labels and then replace them with jQuery?

The model is
CategoryName(string) category axis
ProductName(string) // need THIS label
ProductId(int) //value axis

$("#Chart").kendoChart({
    theme: "default",
    title: {
        text: "Product Categories"
    },
    legend: {
        position: "bottom"
    },
    seriesDefaults: {
        type: "column"
    },
    series: [{
        name: "Product",
        field: "ProductId"
    }],
    valueAxis: {
        labels: {
            template: "#=value#" // I need to replace with a NAME
                 // template: "#= dataItem.ProductName #" // this does NOT work
        }
    },
    categoryAxis: {
       field: "CategoryName"
    },
    tooltip: {
       visible: true,
       template: "#= dataItem.ProductName #" // THIS works
    },
    ... omitted

2 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 19 Jul 2012, 05:23 PM
Ok.. the dataItem property did not do it.. BUT ... placing a function inside the hashmarks DID.. see this post.

The series template configuration supposedly supports dataItem, such as dataItem.[my_string_property]. It does not throw an error, but also didn't change the yAxis label as I needed.

Oh well.. If you're stuck here, surely passing the numeric 'value' to a function will solve anything you can imagine. Telerik should consider updating the documentation,  including an example where a function is used in this way.
        valueAxis: {
                field: "Capability",
                majorUnit: 1,
                minorUnit: 1,
                majorTicks: {
                    visible: false
                },
                majorGridLines: {
                    visible: false
                },   
                labels: {
                    visible: true,
                    template: "#= changeLabels(value) #" // right here!  
                }
            }, 
.. omitted *********************************** 
  
    var Tasks = [
        "Not Applicable",
        "No Shortfalls",
        "Limited Impact",
        "Significant Impacts",
        "Major Risk",
        ""]; // empty 6th value for an empty label
  
    function changeLabels(val)
    {
        return Tasks[val];  // THIS WORKS!!! ! ! !  ! !
    }
</script>
0
Neil
Top achievements
Rank 1
answered on 19 Nov 2012, 09:14 AM
Hey that worked great for the value axis,  is it possible to do the same for category axes ? Because the same code "writes undefined" instead of my custom number
Tags
Charts
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Neil
Top achievements
Rank 1
Share this question
or