Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set chart background in code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Set chart background in code

    Hi.

    I'm trying to set the chart background in code (strategy). I create a brush and apply it inside OnRender() as below but nothing happens.

    ChartControlProperties myProperties = chartControl.Properties;
    myProperties.ChartBackground = myBrush;

    Is there a code example somewhere?

    I need it in realtime rather than historical, if it makes a difference.

    Thanks.

    #2
    Hello digibob,

    I see that our example shows changing these properties in OnRender(). That is very inefficient especially for the property being set in the example.

    I've noted our developers about this.
    I do not recommend that you try and change the ChartBackground in OnRender() if you can avoid it in any way, unless you are wanting to be able to change the color several times a second on each render pass.


    Attached is an example that changes the background in real-time.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea. I was hoping actually to avoid using OnRender(). That's exactly what I need. Many thanks.

      Comment


        #4
        Hello!!
        I want to flip from CrosshairType.Off to CrosshairType.Local but had no success.



        any advice how to achieve it??
        Thank you!!!

        Comment


          #5
          Hello efeuvejota01,

          Thanks for your note.

          You could set the CrosshairType by calling chartControl.CrosshairType within the OnRender() method in a NinjaScript.

          The sample code below demonstrates how to set the CrosshairType to Local.

          Code:
          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
          {
              //Set crosshair type to local
              chartControl.CrosshairType = CrosshairType.Local;
          
              //Print out the current crosshair type
              Print("CrosshairType: " + chartControl.CrosshairType.ToString());
          }
          See this help guide documentation for more information about CrosshairType: https://ninjatrader.com/support/help...sshairtype.htm

          Let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            thank you!! let me try...
            worked perfecly!!

            Thank you!!

            Comment


              #7
              it also work as shown in the attached code...


              Code:
               protected override void OnBarUpdate()
              {
              if (State != State.Realtime)
              return;
              this.Dispatcher.InvokeAsync(() =>
              {
              if (flip)
              { //ChartControl.Properties.CrosshairCrosshairType = CrosshairType.Off;
              ChartControl.CrosshairType = CrosshairType.Off;
              Print("uno");}
              else
              { //ChartControl.Properties.CrosshairCrosshairType = CrosshairType.Local;
              ChartControl.CrosshairType = CrosshairType.Local;
              Print("dos");}
              });
              flip = !flip;
              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              89 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by M4ndoo, 04-20-2026, 05:21 PM
              0 responses
              135 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by M4ndoo, 04-19-2026, 05:54 PM
              0 responses
              68 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by cmoran13, 04-16-2026, 01:02 PM
              0 responses
              119 views
              0 likes
              Last Post cmoran13  
              Started by PaulMohn, 04-10-2026, 11:11 AM
              0 responses
              69 views
              0 likes
              Last Post PaulMohn  
              Working...
              X