[CLOSED] Chart: Creating in behind code and listeners

  1. #1

    [CLOSED] Chart: Creating in behind code and listeners

    Let me see if I can explain this one.

    I am creating my chart in behind code, removing any previous chart from the existing panel and adding the newly created chart. After adding certain features I add to the AfterRender handler to configure certain preferences that the user has previously selected via a ContextMenu.

    Chart byMonthChart = new Chart();
    ...
    // Create: Vertical Marker
    VerticalMarker vm = new VerticalMarker();
    vm.Enabled = false;
    vm.Snap = true;
    vm.ShowXLable = false;
    byMonthChart.Plugins.Add(vm);
    
    // Configure: Enable/Disable VerticalMarker based on Context Menu Option
    if (ShowVerticalMarkers.Checked == true)
       byMonthChart.Listeners.AfterRender.Handler += 'this.plugins[0].enable();";
    else
       byMonthChart.Listeners.AfterRender.Handler += 'this.plugins[0].disable();";
    ...
    ChartPanel.RemoveAll();
    byMonthChart.AddTo(ChartPanel);

    My problem occurs when I append an AfterRender handler for the CategoryAxis to hide/show the gridLines. During the AfterRender the axes.items[0] is not a fully created Axis object and thus gridLines have not been created yet. It is just an Object with {grid: true, position: "bottom", title: "Month", fields: Array[1], type: "Category" }.

    // Create: Category Axis
    CategoryAxis cAxis = new CategoryAxis();
    cAxis.Position = Position.Bottom;
    cAxis.Title = "Month";
    cAxis.Fields = new string[] { "Name" };
    cAxis.Grid = true;  // Assign to true, so the user can show/hide
    byMonthChart.Axes.Add(cAxis);
    
    // Configure: Show/Hide Category Grid Lines based on Context Menu Option
    if (CategoryAxisGrid.Checked == true)
       byMonthChart.Listeners.AfterRender.Handler += "this.axes.items[0].gridLines.show(true)";
    else
       byMonthChart.Listeners.AfterRender.Handler += "this.axes.items[0].gridLines.hide(true)";
    I have tried other listeners (beforeShow), but they are not fired. I assume because the chart is added to an existing panel? Any thought on how I can apply the Context Menu setting to the CategoryAxis before it is shown.
    Last edited by Daniil; Nov 29, 2013 at 2:22 PM. Reason: [CLOSED]
  2. #2
    Hello!

    It's difficult to say how to solve this problem. At first I'd try to add a small delay to the handler. Another way I would create a loop task that checks if axes.items[0] are initialized.
  3. #3
    Quote Originally Posted by cwolcott View Post
    I have tried other listeners (beforeShow), but they are not fired. I assume because the chart is added to an existing panel
    Yes, the BeforeShow and Show events fire when calling the show method.
    http://docs.sencha.com/extjs/4.2.1/#...ent-event-show

    It is not called for initial appearing.

    As for the main issue. Yes, a small Delay for the AfterRender listener might work.
  4. #4
    The delay solved the problem.

    byMonthChart.Listeners.AfterRender.Handler += 
         "var cGrid = App.CategoryAxisGridBtn; 
                      Ext.defer(toggleCategoryAxisGrid, 1, this, [cGrid, cGrid.checked]);";
    There is a blink where you can see the grids for a second before they are hidden, but I can live with that.

    I also had to add a listener on the charts resize so I could apply the show/hide to the gridLines (Category) and gridOdd (Numeric) whenever the window is resized.

    To solve the blink and having to add the resize listener I could just clearout the category and numeric grid objects altogether and recreate on any show, but for now it is good enough.

    Still one more thing I just noticed, if I select a series in the legend the chart redraws and the grids show up again. I need to determine if there is an event that I can capture or just implement my own suggestion above off clearing out the objects and recreate when needed (if possible).
    Last edited by cwolcott; Nov 26, 2013 at 11:13 AM.
  5. #5
    To avoid re-appearing, you, probably, have to set up respective config options like ".grid = false;" along with calling the hide method.

    If you can provide a simple test case to reproduce both the issues - blink and re-appearing on legend click - I could play with that a bit trying to find the best solution.

Similar Threads

  1. [CLOSED] Getting ExtJs error on creating bar chart.
    By PriceRightHTML5team in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 30, 2013, 12:56 PM
  2. Replies: 2
    Last Post: Jun 20, 2013, 10:32 AM
  3. Replies: 3
    Last Post: May 31, 2012, 6:02 PM
  4. Replies: 7
    Last Post: May 17, 2012, 4:31 PM
  5. Replies: 0
    Last Post: Mar 27, 2012, 10:01 AM

Posting Permissions