HELP ! String labels on both axes

3 posts, 0 answers
  1. Michael
    Michael avatar
    1 posts
    Member since:
    May 2009

    Posted 17 Jul 2012 Link to this post

    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. Michael
    Michael avatar
    1 posts
    Member since:
    May 2009

    Posted 19 Jul 2012 Link to this post

    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>
  3. Neil
    Neil avatar
    39 posts
    Member since:
    May 2012

    Posted 19 Nov 2012 Link to this post

    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
Back to Top