[OPEN] [#1540] [4.4.0] Initially hiding a LineSeries in a CartesianChart

  1. #1

    [OPEN] [#1540] [4.4.0] Initially hiding a LineSeries in a CartesianChart

    Previously we could set Hidden=true for a LineSeries to have it disabled initially and a user could select it on the Legend to display it. Now when we set Hidden=true the marker for the series in the legend is hidden also instead of just masked.

    I can get around this problem by using the following listener instead of setting Hidden=true:

    <Listeners>
        <ChartAttached Handler="this.setHidden(true);" Delay="100"></ChartAttached>
    </Listeners>
    Is there a better way to have a series disabled initially -- or is this a bug?

    Below is the example code that shows the issue:

    <%@ Page Language="C#" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Chart1.GetStore().DataSource = new List<object>
            {
                new { Month = "Jan", Data1 = 20, Data2 = 37, Data3 = 35, Data4 = 4 },
                new { Month = "Feb", Data1 = 20, Data2 = 37, Data3 = 36, Data4 = 5 },
                new { Month = "Mar", Data1 = 19, Data2 = 36, Data3 = 37, Data4 = 4 },
                new { Month = "Apr", Data1 = 18, Data2 = 36, Data3 = 38, Data4 = 5 },
                new { Month = "May", Data1 = 18, Data2 = 35, Data3 = 39, Data4 = 4 },
                new { Month = "Jun", Data1 = 17, Data2 = 34, Data3 = 42, Data4 = 4 },
                new { Month = "Jul", Data1 = 16, Data2 = 34, Data3 = 43, Data4 = 4 },
                new { Month = "Aug", Data1 = 16, Data2 = 33, Data3 = 44, Data4 = 4 },
                new { Month = "Sep", Data1 = 16, Data2 = 32, Data3 = 44, Data4 = 4 },
                new { Month = "Oct", Data1 = 16, Data2 = 32, Data3 = 45, Data4 = 4 },
                new { Month = "Nov", Data1 = 15, Data2 = 31, Data3 = 46, Data4 = 4 },
                new { Month = "Dec", Data1 = 15, Data2 = 31, Data3 = 47, Data4 = 4 }
            };
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Line Chart - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <h1>Line Chart Example</h1>
    
            <p>Marked lines are multi-series lines displaying trends across multiple categories.</p>
            <p>Markers are placed at each point to clearly depict their position on the chart.</p>
    
            <ext:Panel
                runat="server"
                Width="650"
                Height="550"
                Layout="FitLayout">
                <TopBar>
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:ToolbarFill runat="server" />
    
                            <ext:Button
                                runat="server"
                                Text="Preview"
                                Handler="this.up('panel').down('chart').preview();" />
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:CartesianChart
                        ID="Chart1"
                        runat="server"
                        InsetPadding="40">
                        <Store>
                            <ext:Store runat="server">
                                <Model>
                                    <ext:Model runat="server">
                                        <Fields>
                                            <ext:ModelField Name="Month" />
                                            <ext:ModelField Name="Data1" />
                                            <ext:ModelField Name="Data2" />
                                            <ext:ModelField Name="Data3" />
                                            <ext:ModelField Name="Data4" />
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:Store>
                        </Store>
    
                        <LegendConfig Dock="Right" />
    
                        <Items>
                            <ext:TextSprite
                                Text="Line Charts - Marked Lines"
                                FontSize="22"
                                Width="100"
                                Height="30"
                                X="40"
                                Y="20" />
    
                            <ext:TextSprite
                                Text="Data: Browser Stats 2012"
                                FontSize="10"
                                X="12"
                                Y="480" />
    
                            <ext:TextSprite
                                Text="Source: http://www.w3schools.com/"
                                FontSize="10"
                                X="12"
                                Y="495" />
                        </Items>
    
                        <Axes>
                            <ext:NumericAxis
                                Position="Left"
                                Fields="Data1,Data2,Data3,Data4"
                                Grid="true"
                                Minimum="0">
                                <Renderer Handler="return label.toFixed(label < 10 ? 1: 0) + '%'" />
                            </ext:NumericAxis>
    
                            <ext:CategoryAxis
                                Position="Bottom"
                                Fields="Month"
                                Grid="true">
                                <Label RotationDegrees="-45" />
                            </ext:CategoryAxis>
                        </Axes>
                        <Series>
                            <ext:LineSeries
                                Title="IE"
                                XField="Month"
                                YField="Data1">
                                <Marker>
                                    <ext:Sprite SpriteType="Square" Duration="200" Easing="BackOut" />
                                </Marker>
    
                                <HighlightConfig>
                                    <ext:Sprite Scaling="2"  />
                                </HighlightConfig>
    
                                <Tooltip TrackMouse="true" StyleSpec="background: #fff;">
                                    <Renderer Handler="var title = context.series.getTitle(); toolTip.setHtml(title + ' for ' + record.get('Month') + ': ' + record.get(context.series.getYField()) + '%');" />
                                </Tooltip>
                            </ext:LineSeries>
    
                            <ext:LineSeries
                                Title="Firefox"
                                XField="Month"
                                YField="Data2"
                                Hidden="true">
                                <Marker>
                                    <ext:Sprite SpriteType="Triangle" Duration="200" Easing="BackOut" />
                                </Marker>
    
                                <HighlightConfig>
                                    <ext:Sprite Scaling="2"  />
                                </HighlightConfig>
    
                                <Tooltip TrackMouse="true" StyleSpec="background: #fff;">
                                    <Renderer Handler="var title = context.series.getTitle(); toolTip.setHtml(title + ' for ' + record.get('Month') + ': ' + record.get(context.series.getYField()) + '%');" />
                                </Tooltip>
                            </ext:LineSeries>
    
                            <ext:LineSeries
                                Title="Chrome"
                                XField="Month"
                                YField="Data3">
                                <Marker>
                                    <ext:Sprite SpriteType="Arrow" Duration="200" Easing="BackOut" />
                                </Marker>
    
                                <HighlightConfig>
                                    <ext:Sprite Scaling="2"  />
                                </HighlightConfig>
    
                                <Tooltip TrackMouse="true" StyleSpec="background: #fff;">
                                    <Renderer Handler="var title = context.series.getTitle(); toolTip.setHtml(title + ' for ' + record.get('Month') + ': ' + record.get(context.series.getYField()) + '%');" />
                                </Tooltip>
                            </ext:LineSeries>
    
                            <ext:LineSeries
                                Title="Safari"
                                XField="Month"
                                YField="Data4">
                                <Marker>
                                    <ext:Sprite SpriteType="Cross" Duration="200" Easing="BackOut" />
                                </Marker>
    
                                <HighlightConfig>
                                    <ext:Sprite Scaling="2"  />
                                </HighlightConfig>
    
                                <Tooltip TrackMouse="true" StyleSpec="background: #fff;">
                                    <Renderer Handler="var title = context.series.getTitle(); toolTip.setHtml(title + ' for ' + record.get('Month') + ': ' + record.get(context.series.getYField()) + '%');" />
                                </Tooltip>
                            </ext:LineSeries>
                        </Series>
                    </ext:CartesianChart>
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
  2. #2
    Hello @tylert!

    Well, while I agree this is definitely a bug with the legend, unfortunately ExtJS documentation on the 'hidden' series feature suggests it may not be fully implemented.

    As a maybe better workaround, you may just hide the series after the chart is built yet before it is rendered. Seems to work just fine. Check it out on the sample you provided with these changes:

    1. Add a script block (optional, for readability)

    <script type="text/javascript">
        var hideSeries = function (item) {
            Ext.each(item.getSeries(), function (entry) {
                if (entry.getTitle() == "Firefox") {
                    entry.setHidden(true);
                };
            });
        };
    </script>
    2. Add the listener to the CartesianChart block:

    <Listeners>
        <BeforeRender Fn="hideSeries" />
    </Listeners>
    I didn't really check out the way you suggested but the Delay="100" clearly lets the user briefly see the chart series before it hides, which I believe is undesirable in your case.

    Anyway, we are going to keep an eye open after this issue and we've notified Sencha about it. We've bound issue #1540 to this and will update here as soon as we get news from Sencha or we decide on fixing it on our own.

    Regardless of that, we hope the listener approach is acceptable for the time being, specially this way allowing you to have a solution that should be compatible across versions.

    Hope this helps!
    Last edited by fabricio.murta; Sep 11, 2017 at 8:58 PM. Reason: add link for github issue
  3. #3
    Thanks for those suggestions. One of these options will work well for us until it is fixed.

Similar Threads

  1. [CLOSED] CartesianChart not showing
    By atroul in forum 4.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 27, 2017, 5:53 AM
  2. Replies: 4
    Last Post: Sep 13, 2016, 5:19 AM
  3. Chart lineSeries renderer
    By brunweb in forum 2.x Help
    Replies: 2
    Last Post: Feb 03, 2014, 3:57 PM
  4. [OPEN] [#40] How can show the labels over each point of the LineSeries?
    By tactime10 in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 17, 2012, 12:43 AM
  5. [CLOSED] How can increase the size line of the lineSeries
    By tactime10 in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 21, 2012, 1:59 PM

Posting Permissions