This project is read-only.

Digital graph

Nov 3, 2009 at 11:34 AM
Edited Nov 3, 2009 at 11:55 AM

Is there support for digital graphs? I did wonder if it could be implemented with a custom marker - would be grateful for any hints.

Examples to explain what I mean by 'digital graph':

http://s906.photobucket.com/albums/ac266/McBainUK/?action=view&current=DigitalGraph2.png

http://zone.ni.com/cms/images/devzone/tut/a/a19b8d1a867.gif

Nov 3, 2009 at 12:21 PM

Hi!

As I have understod from the pictures you've posted, you need some specific processing of input data for line chart. You can yourself write such a processing, and add to linechart already processed sequence of points. In the future I'll add such kind of filter to D3, if I not forget to do it)

If you mentioned something else, please correct me.

 

Regards,

Mikhail.

Nov 3, 2009 at 12:34 PM
Edited Nov 3, 2009 at 12:46 PM

Just to make things clear;

The source data for the first picture is: (x,y) (0,0), (1,1), (2,1), (3,0), (4,1), (5,0). There is no extra point drawn where the blue arrows are, it just only draws the lines at right-angles. With that in mind would the method still be to add an input filter to create a data list something like: (x,y) (0,0), (1,0), (1,1), (2,1), (2,0), (3,0), (3,1), (4,1), (4,0), (5,0) ?

And an explanation from the documentation for the product shown in the second picture: If the current point is represented as (x0, y0) and the next point is represented as (x1, y1), then a line from (x0, y0) to (x1, y0) and (x1, y0) to (x1, y1) represents an XY step.

Thanks

Nov 3, 2009 at 12:56 PM

I think you are right, this follows from pictures you've sent.

Mikhail.

Mar 11, 2011 at 11:11 AM
Edited Mar 11, 2011 at 1:05 PM

Hi,

for others who have this problem: You could use a Filter.

   class StepLineFilter : PointsFilterBase
   {
      double lastX;

      public override List<Point> Filter(List<Point> points)
      {
         int pointsCount = points.Count;
         List<Point> res = new List<Point>(pointsCount * 2);
         for (int i = 0; i < pointsCount; i++)
         {
            res.Add(points[i]);
            if (i < pointsCount - 1)
            {
               res.Add(new Point(points[i + 1].X, points[i].Y));
            }
            else
            {
               res.Add(new Point(lastX, points[i].Y));
            }
         }

         return res;
      }

      public override void SetScreenRect(Rect screenRect)
      {
         lastX = screenRect.X + screenRect.Width;
      }
   }
LineGraph.Filters.Add(new StepLineFilter());

Best regards, Torsten

May 8, 2012 at 7:16 PM

Hey Torsten, 

very usefull and it was exactly what I  needed!

 

I will just need to adapt the SetScreenRect() to stopping drawing a giant plotter in my chart ;)

 

Best regards, Marcus!

Apr 28 at 1:31 AM
Edited Apr 28 at 2:30 AM
Thank you Torsten. you solved my problem.
But your solution has a little problem. When I zoomed the chart applied your solution, the postion of last x point is wrong.
So I modified your source a little.
class StepLineFilter : PointsFilterBase
{
    public override List<Point> Filter(List<Point> points)
    {
        List<Point> ret = new List<Point>();
        Point prevPoint = new Point();
        bool bFirst = true;

        foreach(Point p in points)
        {
            if (bFirst)
            {
                bFirst = false;
            }
            else
            {
                if (prevPoint.Y != p.Y)
                    ret.Add(new Point(p.X, prevPoint.Y));
            }

            ret.Add(p);
            prevPoint = p;
        }

        return ret;
    }
}
Best regards, Leeky