How do I set a brush color to the color of the chart background?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Set Color of Brush to Match Chart Background
Collapse
X
-
Hello,
You can retrieve the background of the chart using ChartControl.Properties:
ChartControl.Properties.ChartBackground
You can locate the other properties in the help guide here: http://ninjatrader.com/support/helpG...b=chartcontrol
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
Hello,
Thank you for the questions.
Are you getting an exception or something while you try the code somewhere else?
ChartControl in general can be null or not, while the sample syntax is correct you still may need to check if the object is null or not before using it.
If you are getting exceptions in the output or log, you may need to utilize :
if(ChartControl != null)
{
myBrushVar = ChartControl.Properties.ChartBackground;
}
If this is not the case, could you tell me what errors or other problems you are running into regarding using the syntax anywhere other than OnRender?
Regarding the forum question, if you click the Go Advanced button while replying, you will get the full editor with Syntax button. The bb code for the syntax block is : [ CODE ] some code here [/ CODE], without the spaces.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Hi Jesse
Previously, when I had
Code:(State == State.Configure) { backgroundBrush = ChartControl.Properties.ChartBackground; }
Is it OK to leave it here or is it better suited elsewhere?
Thanks for the bb code.
Comment
-
Hello,
What you have would in general be OK,
Code:(State == State.Configure) { backgroundBrush = ChartControl.Properties.ChartBackground; }
Code:(State == State.Configure) { if(ChartControl != null) { backgroundBrush = ChartControl.Properties.ChartBackground; } }
JesseNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jesse View PostBut, ChartControl can be null which is an exception if you try to access Properties on the null object, I would suggest any time using ChartControl to wrap it in a null check just in case.
Code:(State == State.Configure) { if(ChartControl != null) { backgroundBrush = ChartControl.Properties.ChartBackground; } }
Question for you Jesse..
How might I go about grabbing the background of the chart from an AddOn in the OnWindowCreated?
Guess more to the point, how might I find and declare the ChartControl of the window/chart?
Comment
-
Originally posted by -=Edge=- View PostI've run across chartcontrol being null in state.config more than once, so setting your brush there might not be the best solution.. If for some reason chartcontrol is null there, your brush never gets set.. I would probably tend to throw that in state.historical, or dataloaded, as I've yet to experience chartcontrol being null in either of those 2 states..
regarding getting the background from an addon, here is a snippet of the OnWindowCreated to do that:
Code:protected override void OnWindowCreated(Window window) { Chart chart = window as Chart; window.Dispatcher.InvokeAsync((() => { if (chart != null) { ChartControl myCC = chart.ActiveChartControl; myCC.Properties.ChartBackground = Brushes.Red; } })); }
JesseNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Jesse View PostGood point made, this would be suggested rather than Configure due to ChartControl being null at certain points, generally DataLoaded or Historical are safe for items like this.
Originally posted by NinjaTrader_Jesse View Postregarding getting the background from an addon, here is a snippet of the OnWindowCreated to do that:
Couple more questions with regards to your sample.. I haven't been using a dispatcher in create, destroy, restore, or save.. I haven't experienced any problems not doing so, but guess the question is.. Should I be using that? ..
Also I've notice in most of the samples I've seen, none of them are calling the base method after any custom coding... base.OnWindowSaved(window, element); Isn't or Is this recommended in all of those states as well?
Comment
-
Originally posted by -=Edge=- View PostCouple more questions with regards to your sample.. I haven't been using a dispatcher in create, destroy, restore, or save.. I haven't experienced any problems not doing so, but guess the question is.. Should I be using that? ..
Originally posted by -=Edge=- View PostAlso I've notice in most of the samples I've seen, none of them are calling the base method after any custom coding... base.OnWindowSaved(window, element); Isn't or Is this recommended in all of those states as well?
Thank you for bringing these items up.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mly916, Today, 09:48 PM
|
0 responses
9 views
0 likes
|
Last Post
by mly916
Today, 09:48 PM
|
||
Started by Mikey_, Today, 09:21 PM
|
0 responses
11 views
0 likes
|
Last Post
by Mikey_
Today, 09:21 PM
|
||
Started by cre8able, Today, 05:53 PM
|
3 responses
13 views
0 likes
|
Last Post
by cre8able
Today, 09:20 PM
|
||
Started by Aryan Kumar, Today, 09:04 PM
|
0 responses
4 views
0 likes
|
Last Post
by Aryan Kumar
Today, 09:04 PM
|
||
Started by yertle, Yesterday, 05:49 PM
|
3 responses
16 views
0 likes
|
Last Post
by Mindset
Today, 08:38 PM
|
Comment