Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

The problem I has is follows:

1. I have a DataGrid table with rows and columns bound to a List<DataStructure> where the DataStructure has Name, MinVal, MaxVal, TodayVal.

2. In my DataGrid, I need to display a chart/graph of all the data values for a list of data points. For example, if X has grades of 78.5, 45.5, 100, 94.5.....etc, the MinVal, MaxVal and TodayVal are based on this list of data points. The graph/chart shows the progress starting wih day1 through to today.

3. The chart has to fit in the datagrid row/column - (no: borders, legends, x/y axis, title....etc). The chart/graph has to be stretched or scaled such that it fits perfectly in the datagrid cell (startpoint left aligned, endpoint is rightaligned).

<dg:DataGridTemplateColumn x:Name="GRADES" Header="GRADE&#13;Chart" IsReadOnly="True" Width="83">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate x:Name="DAILYGRIDTEMPATE">
	<Grid Width="83" ClipToBounds="False">
 		<Canvas Margin="0" ClipToBounds="False" Background="Transparent">
                                    <Polyline Points="{Binding GRADES}" 
                                              Stroke="Blue" 
                                              StrokeThickness="1" 
                                              ClipToBounds="False"
                                              HorizontalAlignment="Stretch"
                                              VerticalAlignment="Stretch"
                                              Stretch="Uniform"/>
                                </Canvas>                                
                         </Grid>
                 </DataTemplate>
         </dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>


My DataStructure contains the following property for the polyline pointcollections (Class = rowModel)

// GradeChart - Point Collection
 public PointCollection _grades;
 public PointCollection GRADES
 {
     get { return _grades; }
     set
     {
         _grades= value;
         OnPropertyChanged(&quot;GRADES&quot;);
     }
 }



My code populates the XAML/WPF by the following (where points = List<double> {76.3, 56.2, 96.4...etc}):

PointCollection pc = new PointCollection();
for (int i = 0; i &lt; points.Count; i++)
{
    pc.Add(new Point(i, (double)points[i]*10));
    Debug.WriteLine(className + &quot;: paintIntradayChart [&quot; + i + &quot;, &quot; + (double)points[i] + &quot;]&quot;);
}
pc.Freeze();
rowModel.GRADES= pc;



Now this all works fine and I can set my chart/graph in the datacell....in fact, I can also have this update intraday if required as all I have to do is add a point to the pointcollection, freeze it and then set it to the GRADES property to reflect the chanege.

What I need to do fix the following which I am sort of struggling with:

1. X/Y coordinates of the Polyline should be like a chart (X -> right, Y -> Up)....currently Y -> Down

2. Scaling of the Polyline in the Canvas - need it to fit perfectly in the Grid -> Canvas

Would appreciate any help. Please provide code snippets as I am new to learning .NET an would appreciate illustrative guidance rather than just general direction.

Thanks,

Manish
Posted
Updated 9-Sep-11 4:03am
v2

1 solution

1) Y is down and that's just the way it is, you should be able to accommodate that easily, all you need to do when you've calculated Y is y = 0-y.
2) You can use ScaleTransform[^] for this, there are examples at the bottom of the page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900