Nov 25, 2013, 12:05 PM
[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.
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" }.
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]