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

Changing the color of a ScatterLine point in Javascript.

3 Answers 59 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Ahmet
Top achievements
Rank 1
Ahmet asked on 28 Aug 2018, 08:22 PM

Hello

I'd like to be able to change the color of a ScatterSeriesItem point upon clicking. I have tried the following in Javascript; However, it didn't work. I'd appreciate for the help.

 

function seriesClick(e) {

  // change the color of the point to red

   e.point.color = "#ff0000"; 

  // redraw the chart

  var chart = $find("chart").get_kendoWidget();
  chart.redraw();

}

 

In C#, I am able to change a point's color by ScatterSeriesItem.BackgroundColor property, however I need to be able to do it in Javascript.

Thanks.

 

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 31 Aug 2018, 04:19 PM
Hi Ahmet,

You can use the e.element instance to achieve this requirement:
https://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/chart/events/seriesclick#seriesClick

Here is a working sample:
function pageLoad(app, args) {
    var chart = $find('<%= ScatterChart.ClientID %>');
    var kendoChart = chart.get_kendoWidget();
    chart.get_kendoWidget().bind("seriesClick", function (e) {
        $(e.element).attr("fill", "#ff0000");
    });
}

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ahmet
Top achievements
Rank 1
answered on 31 Aug 2018, 05:47 PM

Hey Eyup

We aren't using Jquery so is there is any way to get the "attr" function from e.element with pure javascript ? 

I tried to use e.element.attributes("fill, ""#ff0000") but attributes wasn't a function.

I also tried to use e.element.attributes.fill.value = "#ff0000"; but it didn't work either.

Thanks.

0
Eyup
Telerik team
answered on 04 Sep 2018, 11:05 AM
Hello Ahmet,

You can use the following approach for vanilla JS:
e.element.setAttribute("fill", "#ff0000");

Please give it a try and let me know if it works for you.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Chart (HTML5)
Asked by
Ahmet
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Ahmet
Top achievements
Rank 1
Share this question
or