Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

single plot but different colors

Hi all! I've a ScatterGraph with a single plot and I need to show different colors according to x axis ranges: from 0 to 2 should be red, 3 to 5 blue, 6 to 20 yellow and so on. I could use different plots to achieve this but i also need to use a single cursor to scroll all plots. Any suggestion?
0 Kudos
Message 1 of 3
(3,569 Views)

Hello,

 

it's not possible to draw one single plot in different color or style, like it is said at this link.

 

You can have the same results by drawing multiple lines like you already wrote in the previous post, but you'll still have the cursor problem...

 

Ciao,

 

Andrea 

Andrea N.
Principal Applications Engineer - Semiconductor EMEA
National Instruments Italy
Certified LabVIEW Architect - Certified TestStand Architect
0 Kudos
Message 2 of 3
(3,548 Views)

Hello karpediemnow - 

 

This actually can be done, but will require a bit of work on your part.  To achieve this, you will need to create your own custom LineStyle class, inheriting from the NationalInstruments.UI.LineStyle class. You will then need to override the IsContextDependent property, and the CreatePen method.  The basic idea is that your new CreatePen method will return a pen created from a brush that paints quickly changing gradients.  The important code is shown below (this is only a very rough demonstration to get something working - you will need to adapt this code to your own needs):

 

public class ColorChangingStyle : LineStyle
{
   public override bool IsContextDependent
   {
      get { return true; }
   }
   public override Pen CreatePen(object context, LineStyleDrawArgs args)
   {
      using (LinearGradientBrush lgBrush = new LinearGradientBrush(args.ContextBounds,
         Color.Red, Color.Blue, LinearGradientMode.Horizontal))
      {
         ColorBlend colorBlend = new ColorBlend();
         colorBlend.Colors = new Color[] { Color.Red, Color.Red,
            Color.Blue, Color.Blue, Color.Yellow, Color.Yellow };
         colorBlend.Positions = new float[] { 0.0f, 0.0999f,
            0.1001f, .2499f, .2501f, 1.0f };

         lgBrush.InterpolationColors = colorBlend;
         return new Pen(lgBrush, args.Width);
      }
   }
}


You will then assign a new instance of this class to the LineStyle member of your plot. The result will look something like this.

 

NickB12-04, 08_54_07.png

 

For more information, check out the help topic "Creating a Custom Line Style for the Measurement Studio Web Forms Graph .NET Controls".  Let me know if you have any questions.

 

NickB

National Instruments 

0 Kudos
Message 3 of 3
(3,543 Views)