How do I implement charts in WPF?

Solution
Using the template on this web site - stackoverflow.com/questions/33756255/create-a-math-plot-in-c-sharp-xam

.xaml

C#:
<Canvas x:Name="gCanvasPlot0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,0,0,0"
Width="500"
Height="150" />

.cs

C#:
//------------------------------
private void AddPlot()
{
double dPI = Math.PI;

Polyline poXY = new Polyline {
Stroke = Brushes.Red
};
int iNumOfCycles = 3;
double dDeltaX = 0.01;
int iNumOfPoints0 = (int)(iNumOfCycles / dDeltaX);
for (int ii = 0; ii < iNumOfPoints0; ii++) {
double dX = ii * dDeltaX;
double dY = Math.Sin(2 * dPI * dX);
poXY.Points.Add(CorrespondingPoint(new Point(dX, dY), iNumOfCycles));
}
gCanvasPlot0.Children.Add(poXY);
}//AddPlot...
I don't think WPF has any built in charting library. You'll need to either use a free open source one, or pay for one of the big guys like Telerik or DevExpress.

If all you need to do is plot some sine waves (based on your other thread), it shouldn't be that hard to use WPF's drawing directly.

 
It's surprising that Chart is not standard for WPF. It is trivial to use in Forms.

Is there sample code for using WPF's drawing directly for an xy plot?
 
Last edited:
The Charts in WinForms essentially just used the MS Chart Controls which are GDI based. WPF uses DirectDraw. They would have had to port code over into the WPF way of doing things.
 
I've been unable to find a WPF DirectDraw that creates an xy plot. Not sure where to start in xaml. DataGrid provides a grid, not xy area.
 
See the link I provided. It has both declarative XAML, and programmatic C# ways of drawing a line. You are going to have to use the programmatic way.
 
I've been there. As far as I can tell, those are predefined shapes. Where do I find a way to plot a sequence of numbers?
 
As points? Or as lines between the points?
 
I have tried this:

for (int ii = 1; ii < 99; ii++) { myLine.X1 = (double)ii; myLine.Y1 = (double)ii; myLine.X2 = (double)ii + 1; myLine.Y2 = (double)ii + 1; gCVPlot.Children.Add(myLine); }

When ii = 2, I get a Exception.
 
Add a PolyLineSegment to the Path.
 
I've been there. As far as I can tell, those are predefined shapes. Where do I find a way to plot a sequence of numbers?
See link that you said you've already visited. Go about 2/3rd of the way down the page where a PolyLineSegment is demonstrated.
 
Back
Top Bottom