2

I am new to jquery and javascript. I am making a pie-chart and I want to highlight the pieces of pie-chart. I have succeeded in making a pie-chart but the problem with me is me on highlighting.

I have to highlight every piece of pie when mouse is over it. Now, when I search it on google then there are various plug-in avalible but is there a way to do without it. I tried by creating a jquery function and then when mouseover it should change highlight but I cannot do it by that way.

Here is my code---

<html> <body> <canvas width="500" height="500" id="canvas"></canvas> <script> //initialize data set var data = [ 100, 68, 20, 30, 100 ]; var canvas = document.getElementById('canvas'); var c = canvas.getContext('2d'); //draw background c.fillStyle = "white"; c.fillRect(0,0,500,500); //a list of colors var colors = [ "orange", "green", "blue", "yellow", "teal"]; //calculate total of all data var total = 0; for(var i=0; i<data.length; i++) { total += data[i]; } //draw pie data var prevAngle = 0; for(var i=0; i<data.length; i++) { //fraction that this pieslice represents var fraction = data[i]/total; //calc starting angle var angle = prevAngle + fraction*Math.PI*2; //draw the pie slice c.fillStyle = colors[i]; //create a path c.beginPath(); c.moveTo(250,250); c.arc(250,250, 100,prevAngle, angle, false); c.lineTo(250,250); //fill it c.fill(); //stroke it c.strokeStyle = "black"; c.stroke(); //update for next time through the loop prevAngle = angle; } </script> </body> </html> 

Pie chart should be highlighted something like below: enter image description here

Please help me with this. I know it simple but I am not able to figure out. Any help is appreciated. Please comment if you have any question?

16
  • you want the value of the pie share to be shown on hovering over it ? Commented Apr 28, 2016 at 6:12
  • I have edited the question. Added a image I want something like this. Commented Apr 28, 2016 at 6:18
  • 1
    you need to set "sliced: true, selected: true" for the series you need check this link jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/… Commented Apr 28, 2016 at 6:34
  • @Raki here they have sliced:true to appear it different from others but I want when the cursor is there then it should be highlighted. But I don't want that I want when cursor is there it should be highlighted. Commented Apr 28, 2016 at 6:50
  • Check this updated fiddle with setTranslation function on hover jsfiddle.net/63eh9aty/1 Commented Apr 28, 2016 at 7:06

1 Answer 1

1

@Shubham Vashishtha: check this fiddle. http://jsfiddle.net/63eh9aty/2/ Here I have created a Json variable options which has required setting for highcharts, then next step is to add data to the series. which is implemented by creating a Json variable called "seriesOptions which contains name, data: [ ] (which is array). In order to insert actual data into data:[ ] i have created dataOptions variable. Next assigning data to dataOptions and adding each dataOptions to the seriesOptions finally adding seriesOptions data to the actual series of highchart .i.e options.series.push(seriesOptions) as shown in the fiddle.

Sign up to request clarification or add additional context in comments.

5 Comments

that is very good...thank you so much for your effort...can you please just tell me how do I know which keyword is used for which property. Like if want any other functionality so where can I check?
you can refer this api.highcharts.com/highcharts, if my answers were helpful kindly vote.
yeah, it was very helpful...thank you again...One more thing can you please tell me how to remove that top-right icon that is used for print chart icon etc..I visited the [api.highcharts.com/highcharts] page but couldn't find it
well it is called exporting option. which can be enabled or disabled by adding exporting: { enabled: false } for more details refer api.highcharts.com/highcharts#exporting
@ShubhamVashishtha I hope your problem is solved.... Happy something worked out for you :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.