Donut Chart with center label

3 posts, 1 answers
  1. Jorge
    Jorge avatar
    2 posts
    Member since:
    Jan 2015

    Posted 29 Oct 2015 Link to this post

    Hi!

     Is it possible to set the greater value on the center of the donut? The goal is to reach something like picture attached. Thanks in advance for any help

  2. Answer
    Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 30 Oct 2015 Link to this post

    Hello,

    The desired functionality is not supported by the donut chart out of the box. You can, however, create a label that has an absolute position over the donut and set its value according to the target donut value. For example:

    <head runat="server">
        <title></title>
        <style type="text/css">
            .Label1 {
                position: absolute;
                color: white;
                font-weight: bold;
                font-size: 40px;
                top: 110px;
                left: 93px;
            }
        </style>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function pageLoad() {
                    updateDonutAndLabel();
                }
                function updateDonutAndLabel() {
                    //generate random value
                    var randNum = function (min, max) {
                        return Math.floor(Math.random() * (max - min + 1)) + min;
                    }
                    var currValue = randNum(0, 33);
     
                    //set random value to the chart
                    var chart = $find('<%=RadHtmlChart1.ClientID%>')
                    chart._chartObject.options.series[0].data[0].value = currValue;
                    chart._chartObject.options.series[0].data[1].value = 100 - currValue;
     
                    //Set hole size and remove gradient
                    chart._chartObject.options.series[0].holeSize = 60;
                    chart._chartObject.options.series[0].overlay = { gradient: "none" };
                    chart.repaint();
     
                    //set the current value to the label
                    var label = $get("<%=Label1.ClientID %>");
                    label.textContent = currValue + " %";
                }
            </script>
        </telerik:RadCodeBlock>
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <telerik:RadHtmlChart ID="RadHtmlChart1" runat="server" Width="250px" Height="250px">
                <Appearance FillStyle-BackgroundColor="#C87545"></Appearance>
                <PlotArea>
                    <Series>
                        <telerik:DonutSeries>
                            <LabelsAppearance Visible="false"></LabelsAppearance>
                            <SeriesItems>
                                <telerik:PieSeriesItem Y="0" Name="Item1" BackgroundColor="#FFC700" />
                                <telerik:PieSeriesItem Y="0" Name="Item2" BackgroundColor="#6E443D" />
                            </SeriesItems>
                        </telerik:DonutSeries>
                    </Series>
                </PlotArea>
                <Legend>
                    <Appearance Visible="false"></Appearance>
                </Legend>
            </telerik:RadHtmlChart>
            <asp:Label ID="Label1" Text="10" runat="server" CssClass="Label1" />
            <br />
            <telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="false" OnClientClicked="updateDonutAndLabel" Text="Update Donut and Label" />
        </form>
    </body>
    </html>

    I have also created a code library with this example here - http://www.telerik.com/support/code-library/put-label-in-donut-chart-center

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jorge
    Jorge avatar
    2 posts
    Member since:
    Jan 2015

    Posted 30 Oct 2015 in reply to Danail Vasilev Link to this post

    Thanks a lot. I'll try it right away! It would be great if you consider something like this for future releases, that behavior is kind of common in some graph components (javascript the most of them), but would be really great to have it on telerik. Thanks again
Back to Top