You must be logged in to post your query.
Home › Forums › Chart Support › How to get the color/color code of the legend icon which is assigned to charts.
Tagged: get the color/color code of the legend icon
Want to know if we can get the color of the legend icon which is assigned to that part in the graph or chart.
specially in pie charts.
We haven’t set any color to the chart in data points. it is generating from the default color set.
please help
thank you manoj
Here is the jsfiddle links to the issue.
//want to get the legend color value/code of PlayStation 3. i.e BLUE
console.log(e.dataPoint); inside indexLabelFormatter
thank you manoj kumar
manoj kumar,
You can get the color of legend by using selectedColorset property of chart and index of dataPoint as shown in the code snippet below
indexLabelFormatter: function (e) { var dpIndex = getDataPointIndex(e.dataSeries, e.dataPoint); var selectedColorSet = chart.get("selectedColorSet"); var legendColor = e.dataPoint.legendMarkerColor ? e.dataPoint.legendMarkerColor : (e.dataPoint.color ? e.dataPoint.color : selectedColorSet[dpIndex % (selectedColorSet.length-1)]); console.log(legendColor); } . . . function getDataPointIndex(dataSeries, dataPoint) { return dataSeries.dataPoints.findIndex(dp => dp === dataPoint); }
Also, please take at this updated JSFiddle for complete working code.
—- Manoj Mohan Team CanvasJS
You must be logged in to reply to this topic. Login/Register