Thursday, August 1, 2019

C# code for get SVG donut chart

   

  private string getSvgDonutCircle(int value)
        {
            int diff = 100 - value;
            string html = "<svg viewBox='-5 -5 30 30' class='donut'>" +
               "<circle class='donut-hole' cx='11' cy='11' r='10' fill='#fff'></circle>" +
               "<circle class='donut-ring' cx='11' cy='11' r='10' fill='transparent' " +
               "stroke='#E1E1E1' stroke-width='2'></circle>" +
               "<circle class='donut-segment' cx='11' cy='11' r='10' fill='transparent' " +
               "stroke='" + getColorCode(value) + "' stroke-width='2' stroke-dasharray='" + value + " " + diff + "' stroke-dashoffset='65'></circle>" +
               "<g class='chart-text'>" +
               "<text x='40%' y='44%' class='chart-number'>" + value + "</text>" +
               "</g></svg>";
            return html;
        }

        private string getColorCode(int value)
        {
            if (value < 70 && value > 31)
            {
                return "#F39000";
            }
            else if (value > 70)
            {
                return "#00A13A";
            }
            else if (value < 31)
            {
                return "#AF022B";
            }
            return "";
        }

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...