1

My circle starts from 12 o clock. But I need to start from 7 and end at 5 . Always starts horizontally but I need to start vertically . Also how to add Effects like shadow etc.

var amount = ("80");


var archtype = Raphael("canvas", 600, 400);
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = xloc + R * Math.cos(a),
        y = yloc - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
        ];
    } else {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    return {
        path: path
    };
};

//make an arc at 50,50 with a radius of 30 that grows from 0 to 40 of 100 with a bounce
var my_arc = archtype.path().attr({
    "stroke": "#f00",
    "stroke-width": 14,
    arc: [200, 200, 0, 100, 60]
});

my_arc.animate({
    arc: [200, 200, amount, 100, 60]
}, 1500, "bounce");
Vishnu
  • 741
  • 1
  • 7
  • 24
  • See also: http://stackoverflow.com/questions/5083221/drawing-a-half-gauge-speedometer-javascript-canvas-or-java-swing-example-needed/5632389#5632389 – Spudley Sep 03 '13 at 15:34

2 Answers2

0

Tiny update to make this work on IE8.
You need to remove the extra comma at the end of the path array else IE8 will give a JS error.

var arcseg = function (cx, cy, radius, start_r, finish_r) {
  start_r = Raphael.rad(start_r);
  finish_r = Raphael.rad(finish_r);

  var start_x = cx + Math.cos( start_r ) * radius,
  start_y = cy + Math.sin( start_r ) * radius,
  finish_x = cx + Math.cos( finish_r ) * radius,
  finish_y = cy + Math.sin( finish_r ) * radius,
  path;

  path = [
    [ "M", start_x, start_y ],
    [ "A", radius, radius, finish_r - start_r,
      (finish_r - start_r > Raphael.rad( 180 )) ? 1 : 0, 
      (finish_r > start_r) ? 1 : 0,        
      finish_x, finish_y ]              
  ];
  return { path: path };
};
Community
  • 1
  • 1
Kevin Nielsen
  • 4,413
  • 21
  • 26
0

i finally found it :D just added my_arc.rotate(215, 100 ,100)

<script >

var amount = ("50");


var archtype = Raphael("canvas", 300, 200);
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = xloc + R * Math.cos(a),
        y = yloc - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
        ];
    } else {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    return {
        path: path
    };
};

//make an arc at 50,50 with a radius of 30 that grows from 0 to 40 of 100 with a bounce
var my_arc = archtype.path().attr({
    "stroke": "#f00",
    "stroke-width": 14,
    arc: [100, 100, 0, 100, 60]
});

my_arc.rotate(215, 100 ,100).animate({
    arc: [100, 100, 80, 100, 60]
}, 2000, "bounce");
Vishnu
  • 741
  • 1
  • 7
  • 24