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 NullPointStrategies, Today, 05:17 AM
              0 responses
              51 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              128 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              69 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X