Page 1 of 1

Filling a line series with color

Posted: Thu Oct 17, 2013 8:59 pm
by 9347200
Hi,

I have a question about filling a line series with color. I would like to fill a line series in one direction with color.
An example would be I have a line series "Test" with about 10 points, I take the avg of the 10 points and draw another line using the avg value. Now i want all the values lying above the avg to be colored on the series Test.

I tried to do this using the series band tool, the first series is the actual series called Test and the second series will the line drawn using the avg value. The issue here is there is no way I can specify on fill those values which are great than the avg. This fills values both greater than and lesser than mean.

To be brief, I would like to color the peaks and leave the troughs uncolored. Is there a way to do this ?

Thanks,

Re: Filling a line series with color

Posted: Fri Oct 18, 2013 8:07 am
by narcis
Hi Activex7,

Given your nick and that your previous questions are in the TeeChart ActiveX forum, I'll answer this with an ActiveX example:

Code: Select all

Private Sub Form_Load()
    TChart1.Aspect.View3D = False
    
    TChart1.AddSeries scLine
    TChart1.Series(0).FillSampleValues 50
    
    TChart1.AddSeries scLine
    TChart1.Series(1).SetFunction tfAverage
    TChart1.Series(1).DataSource = TChart1.Series(0)
    
    TChart1.Environment.InternalRepaint
    
    Dim Avg As Double
    Avg = TChart1.Series(1).YValues.Value(0)
    
    For i = 0 To TChart1.Series(0).Count - 1
        If TChart1.Series(0).YValues.Value(i) > Avg Then
            TChart1.Series(0).PointColor(i) = vbRed
        End If
    Next
End Sub
Same applies to TeeChart for .NET though.

Re: Filling a line series with color

Posted: Fri Oct 18, 2013 3:58 pm
by 9347200
Hi Narcis,

This is a teechart.net question. We have multiple licenses for both activex and .NET

Just tried what you sent and instead of

TChart1.Series(0).PointColor(i) = vbRed

I am using

Tchart1.Series[0].Colors=color.blue;

This does not work as I want to fill in the curve, not change the line color of the curve.

I attached a example, as image. In this image both the high and lows are filled with color. Assuming the line passing through the middle is avg. Can I just fill in the peaks (highs) ?

Re: Filling a line series with color

Posted: Mon Oct 21, 2013 12:03 pm
by narcis
Hi Activex7,
This is a teechart.net question. We have multiple licenses for both activex and .NET
Ok, apologies for my wrong assumption.
This does not work as I want to fill in the curve, not change the line color of the curve.

I attached a example, as image. In this image both the high and lows are filled with color. Assuming the line passing through the middle is avg. Can I just fill in the peaks (highs) ?
I did a similar example here. This is a Delphi example. In .NET you can do something like the code below using CrossPoints function and HighLow series.

Code: Select all

      tChart1.Aspect.View3D = false;
      tChart1.Legend.CheckBoxes = true;

      Line line1 = new Line(tChart1.Chart);
    
      Line line2 = new Line(tChart1.Chart);
      Steema.TeeChart.Functions.Average avg1 = new Steema.TeeChart.Functions.Average();
      line2.Function = avg1;
      line2.DataSource = line1;

      line1.FillSampleValues();

      tChart1.Draw();

      double avg = line2.YValues[0];

      Points points1 = new Points(tChart1.Chart);
      Steema.TeeChart.Functions.CrossPoints crossPoints1 = new Steema.TeeChart.Functions.CrossPoints();
      points1.DataSource = new object[] { line1, line2 };
      points1.Function = crossPoints1;

      HighLow highLow1 = new HighLow(tChart1.Chart);
      highLow1.HighBrush.Visible = true;

      int j = 0;

      for (int i = 0; i < line1.Count; i++)
      {
        double y = line1.YValues[i];

        if (y > avg)
        {
          double x = line1.XValues[i];
          highLow1.Add(x, y, avg);
        }
        else
        {
          double x = points1.XValues[j];
          highLow1.Add(x, avg, avg);
          j++;
        }
      }

Re: Filling a line series with color

Posted: Tue Oct 22, 2013 10:51 pm
by 9347200
Hi Narcis,

Thanks for the suggestion. However I have another issue, does this work if the curve is along the y axis ? I tried the highlow and it only seems to work for a curve along the x-axis.
The code does not seem to work if the value axis is the x-axis ? Can you please let me know ?

Thanks

Re: Filling a line series with color

Posted: Thu Oct 24, 2013 2:56 pm
by 10050769
Hello Activex7,

Could you try to use a horizLine to achieve as you want? If it doesn't help please let me know.

Thanks,