P
P
Pitonist2242020-02-14 22:33:58
WPF
Pitonist224, 2020-02-14 22:33:58

How to draw a graph with hatching in c#?

You need to make such a chart
5e46f4cd25a5c199571249.png
. The principle is clear:
using livecharts, I immediately draw a step line, shade everything inside
stepline.jpg
and then draw a regular line on top
. But, the only problem is that I don’t know how to shade the first chart (step line) in livecharts.
Or would you recommend using another lib?
Probably there must be a ready-made hatching method somewhere.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pitonist224, 2020-02-16
@Pitonist224

I wrote something myself, looked at something on the Internet and got this:

public static Brush HatchBrush
        {
            get
            {
                var canvas = new Canvas();

                canvas.Children.Add(new Path
                {
                    Stroke = Brushes.Black,
                    StrokeThickness = 1,
                    Data = new LineGeometry(new Point(0, 0), new Point(40, 40))
                });

                var myHathBrush = new VisualBrush
                {
                    TileMode = TileMode.Tile,
                    Viewport = new Rect(0, 0, 10, 10),
                    ViewportUnits = BrushMappingMode.Absolute,
                    Visual = canvas
                };

                return myHathBrush;
            }
        }

5e495886b8651311406463.png
If you need to change the size, distance, then you should play around with the values.

G
Griboks, 2020-02-14
@Griboks

I don't know much about graphs in WPF, so I advise you to use GDI+ and manually draw everything you need. This is easy enough to do using the usual methods of the Graphics object created from, for example, an Image (Bitmap).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question