set(String propertyName, Mixed value [,Boolean updateChart = true])

Sets the value of specified property in crosshair.

Parameters:
        propertyName: Name of the property.
        value: Value to be set on property.
        updateChart: When true, updates the chart after setting the value. Defaults to true.

Example: chart.axisX[0].crosshair.set(“snapToDataPoint”, true)
Note:
  • Chart should be rendered before you can use this method.
  • Because the chart updates each time set is called by default, it is recommended to disable auto update (set updateChart to false) till the last step if you have to set multiple properties. Otherwise it can affect performance because of repeated chart rendering. You can see an example below.
var chart = new CanvasJS.Chart("container",
{ 
 .
 .
   axisX: {
     crosshair: {
       enabled: true,
       snapToDataPoint: false
     },
     .
   },
 .
 .
});
chart.render();

chart.axisX[0].crosshair.set("snapToDataPoint", true);

Properties that can be set via this method

Please refer to crosshair element for the complete list of properties that can be accessed via set method.

Try Editing The Code


If you have any questions, please feel free to ask in our forums.Ask Question