[CLOSED] How to change individual slice pie color

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] How to change individual slice pie color

    Hello,

    I'd like to change the color of slices from pie chart, based on their data.

    I saw the example in link https://examples2.ext.net/#/Chart/Pie/Pie_Renderer/ and I need to change the function segmentRenderer to change color, but it didn't work well.

    <%@ Page Language="C#" Culture="en-CA" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <script runat="server">
        public List<object> Data
        {
            get
            {
                return new List<object>
                {
                    new {Name = "On Time", Data1 = 50 },
                    new {Name = "Delayed", Data1 = 20 },
                    new {Name = "Another", Data1 = 30 },
                };
            }
        }
    </script>    
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Pie Chart - Ext.NET Examples</title>
        <%--<link href="/resources/css/examples.css" rel="stylesheet" />--%>
        
        <script>
            var tipRenderer = function (storeItem, item) {
                //calculate percentage.
                var total = 0;
    
                App.Chart1.getStore().each(function (rec) {
                    total += rec.get('Data1');
                });
                
                this.setTitle(storeItem.get('Name') + ': ' + Math.round(storeItem.get('Data1') / total * 100) + '%');
            };
    
            function segmentRenderer(sprite, record, attr, index, store) {
                if (record.get('Name') == 'On Time') { color = "green" };
                if (record.get('Name') == 'Delayed') { color = "red" };
                if (record.get('Name') == 'Another') { color = "blue" };
    
    
                return Ext.apply(attr, {
                    fill: color
                });
            };
    
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <h1>Pie Chart Example</h1>
    
            <ext:Panel
                runat="server"
                Width="800"
                Height="600"
                Title=""
                Layout="FitLayout">
                <Items>
                    <ext:Chart ID="Chart1" runat="server" Animate="false" Shadow="true" InsetPadding="60" 
                        Theme="Base:gradients">
                        <LegendConfig Position="Right" />
                        <Store>
                            <ext:Store ID="Store1" runat="server" Data="<%# Data %>">
                                <Model>
                                    <ext:Model ID="Model1" runat="server">
                                        <Fields>
                                            <ext:ModelField Name="Name" />
                                            <ext:ModelField Name="Data1" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
                        <Series>
                            <ext:PieSeries AngleField="Data1" ShowInLegend="true" Donut="30" Highlight="true"
                                HighlightSegmentMargin="20">
                                <Label Field="Name" Display="Rotate" Contrast="true" Font="18px Arial" />
                                <Tips ID="Tips1" runat="server" TrackMouse="true" Width="140" Height="28">
                                    <Renderer Fn="tipRenderer" />
                                </Tips>
                                <Renderer Fn="segmentRenderer" />
                            </ext:PieSeries>
                        </Series>
                    </ext:Chart>
                </Items>
            </ext:Panel>
        </form>    
    </body>
    </html>
    Please, could you help me to make this work.

    thanks,

    Oliver
    Last edited by Daniil; Jan 30, 2015 at 12:16 PM. Reason: [CLOSED]

Similar Threads

  1. [CLOSED] Change Color Window's Header Background Color
    By rguardado in forum 3.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 16, 2015, 3:48 PM
  2. [CLOSED] Change TreePanel background color and toolbar color
    By jchau in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 07, 2012, 4:42 PM
  3. [CLOSED] Highlight a slice of pie chart programmatically
    By jchau in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 12, 2012, 12:23 PM
  4. [CLOSED] Individual Image for Grid ImageCommand
    By macap in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 28, 2010, 7:51 AM
  5. Replies: 12
    Last Post: Jun 17, 2009, 12:07 PM

Tags for this Thread

Posting Permissions