33

I have to show progress graphs exactly in following way where percentage would be in center of circular graph
circular progress indicator

How can i do this using javascript/jQuery? Can it be done using Google Chart?

Brij
  • 6,086
  • 9
  • 41
  • 69

6 Answers6

54

There's a plugin for this at: http://anthonyterrien.com/knob/

Demo

jQuery Knob

  • canvas based ; no png or jpg sprites.
  • touch, mouse and mousewheel, keyboard events implemented.
  • downward compatible ; overloads an input element...
Shog9
  • 156,901
  • 35
  • 231
  • 235
mnowotka
  • 16,430
  • 18
  • 88
  • 134
  • Only problem with that plugin is that it displays the value in an input box. Do you know of another that can take any HTML? So that I can put a value (text), an icon (image), and some other text in there. – user1482003 Jun 26 '12 at 22:58
  • It doesn't need an input box to work. This is just one of examples. It has an API, just read the documentation and ask if you have any problems. – mnowotka Jun 27 '12 at 06:27
  • How can i make this type of progress in android ? – kyogs Jan 18 '13 at 12:25
  • Just what I was looking for. It's much better than other libraries I've found, because it doesn't use any pictures and is highly modifiable. – Nullius Sep 10 '14 at 19:35
  • Merged from http://stackoverflow.com/questions/11202920/circular-radial-progress-bar – Shog9 Oct 14 '16 at 21:10
  • I prefer SVG based charts to the canvas based approach, because SVG images stay "sharp" even when zooming in (e.g. in iOS Safari). An alternative plugin is: https://www.isg-software.de/progresspie/examples.html – immo Jan 06 '20 at 18:49
4

I searched and know there are at least 5 ways to create Circular progress indicator:
They include:

  1. jquery.polartimer.js
  2. jQuery Knob
  3. CSS3 pie graph timer with jquery
  4. circular progressBar by jQuery andCSS3
  5. ProgressBar.js
Willem
  • 398
  • 1
  • 6
  • 23
aisin
  • 1,107
  • 7
  • 11
3

I would recommend Highcharts JS for all of your JavaScript graphing needs

Browse through more of the demos; I think you're looking for the Donut Chart :)

maček
  • 76,434
  • 37
  • 167
  • 198
  • i didn't find exactly similar to the image where percentage is in center of circle. – Brij Feb 15 '11 at 09:57
1

If you are not targeting old browsers, you can easily do that by drawing on a canvas element. This gives you the freedom to do whatever you need with the chart.

That means this solution's only requirement is jQuery and any browser that supports the canvas element...IE9+ Here's a code snippet that demonstrates it...

//input
var dimens = 256;
var color = "rgba(54, 162, 235, 0.9)";
var padding = 12;
var width = 10;
var value = 80;
var maxValue = 100;
var countFontRatio = 0.25; //ratio in relation to the dimens value

$(function() {
  $(".chart-total").each(function(idx, element) {

    var _render = function() {

      var startingPoint = -0.5;
      var pointValue = startingPoint;
      var currentPoint = startingPoint;
      var timer;
      var _ctx;

      var $canvas = $(element).find("canvas");
      var canvas = $canvas.get(0);

      pointValue = (value / (maxValue / 20) * 0.1) - 0.5;

      canvas.height = dimens;
      canvas.width = dimens;

      if (!countFontRatio)
        $canvas.parent().find(".legend-val").css("font-size", dimens / value.toString().length);
      else
        $canvas.parent().find(".legend-val").css("font-size", dimens * countFontRatio);

      _ctx = canvas.getContext("2d");



      var _draw = function() {

        _ctx.clearRect(0, 0, dimens, dimens);
        _ctx.beginPath();
        _ctx.arc(dimens / 2, dimens / 2, (dimens / 2) - padding, startingPoint * Math.PI, 1.5 * Math.PI);
        _ctx.strokeStyle = "#ddd";
        _ctx.lineWidth = 2;
        _ctx.lineCap = "square";
        _ctx.stroke();

        _ctx.beginPath();
        _ctx.arc(dimens / 2, dimens / 2, (dimens / 2) - padding, startingPoint * Math.PI, currentPoint * Math.PI);
        _ctx.strokeStyle = color;
        _ctx.lineWidth = width;
        _ctx.lineCap = "round";
        _ctx.stroke();

        currentPoint += 0.1;

        if (currentPoint > pointValue) {
          clearInterval(timer)
        }

      };

      timer = setInterval(_draw, 100);
    };

    _render();

    $(window).resize(function() {
      _render();
    });

  });
})
body {
  font-family: 'Open Sans', sans-serif;
  color: #757575;
}

.chart-total {
  position: relative;
  margin: 0 auto;
}

.chart-total-legend {
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translateY(-50%) translateX(-50%);
  -o-transform: translateY(-50%) translateX(-50%);
  -moz-transform: translateY(-50%) translateX(-50%);
  -moz-transform: translateY(-50%) translateX(-50%);
  transform: translateY(-50%) translateX(-50%);
}

.legend-val {
  font-size: 4em;
  display: block;
  text-align: center;
  font-weight: 300;
  font-family: 'Roboto', sans-serif;
}

.legend-desc {
  display: block;
  margin-top: 5px;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto:300,400" rel="stylesheet">

<div class="chart-total" style="max-width: 256px;">
  <canvas height="256" width="256"></canvas>
  <div class="chart-total-legend">
    <span class="legend-val" value="3933" style="font-size: 64px;">3,933</span>
    <span class="legend-desc">Total Progress</span></div>
</div>
Leo
  • 14,625
  • 2
  • 37
  • 55
1

You can use CSS sprites (google) for this purpose, if you want to show multiples of 10 (0%, 10%, 20% etc). I guess you need to be a graphics guru to create the sprite..

The sprite is one image containing more than one image. For your purpose, you can create an image, say 16x160px. Imagine that this image is divided into ten 16x16px "slices" and draw the corresponding percentage on that slice. You can then use CSS and JavaScript to show one "frame" from this sprite.

Salman A
  • 262,204
  • 82
  • 430
  • 521
0

I don't think you can do it with javascript/jquery/css alone. You need to render different images, for each step one and display the proper one. It could be made with flash (probably there are ready made components) or with svg or html5 canvas element or an api which uses one of the above backends.

Christian
  • 3,551
  • 1
  • 28
  • 24