Search code examples
kendo-uikendo-asp.net-mvckendo-dataviz

How to change a line chart series's color according to the point's value in Kendo UI?


For example, I have a series which have 5 points and their values are 5,10,15,20,25, now I want to change the color of the part series which contains point1(value:5) to point2(value:10) to be red, and want to change the color of the part series which contains point2(value:10) to point2(value:15) to be green, and so on, How to do that? Now I can change the color of the whole series, but do not know how to change the part of the series according to its value?

change the whole series

function onDataBound(e) {
    e.sender.options.series[0].color= "red";   
}

Just like this example, I now can change the color of the point, but can not change the line between the start point and end point.my example


Solution

  • The color option of the series can be set to a function which will be called during rendering. Here is a short demo:

    <div id="chart"></div>
    <script>
    $("#chart").kendoChart({
      series: [{
        data: [1, 2],
        color: function(point) {
          if (point.value > 1) {
            return "red";
          }
    
          // use the default series theme color
        }
      }]
    });