This is a migrated thread and some comments may be shown as answers.

(Graph)Need help with displaying array of coordinates as Line Graph

5 Answers 100 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mats
Top achievements
Rank 1
Mats asked on 09 Sep 2013, 06:53 AM
I'm new to Telerik Reporting and I think that it looks like a great product. However I am stumped as how to achieve something that to me sounds like something trivial.
I have an array of coordinates, a class with two properties; X and Y, and want to create a graph that displays these as a smooth line. I create the graph and bind to the array but I have no clue as how to specify that it should use the properties X and Y to place the line.

Right now I have this in my series and it doesn't work at all. I've also tried just =Fields.X
X =Fields.HeadGraph.Polynom.CalculatedPoints[i].X
Y =Fields.HeadGraph.Polynom.CalculatedPoints[i].Y


I feel that must be missing something trivial and any help that can get me forward is greatly appreciated.

BR,
Mats

5 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 10 Sep 2013, 02:43 PM
Hi Mats,

Generally I'd recommend the Graph Wizard when creating a new graph, which is more intuitive and easy to use.

If you want to avoid the wizard to create your graph you can refer to the How to: Create Line Chart help article for more information.

If you are using the Graph Wizard follow these steps to create your graph:
  1. Drag and drop the Graph Wizard from the Visual Studio toolbox to your report.
  2. Select your desired Chart Type.
  3. Select/Add New Data Source. The data source I used in my test graph is of type ObjectDataSource and looks like this.
  4. Drag the X field and the Y field to the appropriate boxes.


Regards,
Nasko
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Mats
Top achievements
Rank 1
answered on 10 Sep 2013, 07:27 PM
Ok! Thanks for the great reply btw... :-)

I found my issue now. The method in my datasource returns a big object containing data for the whole report. The object contains both string-properties for textfields as well as data for three different graphs.

The object looks like this (trimmed somewhat)
public class TestDTO
{
    public string InfoType { get; set; }
    public Nullable<System.DateTime> TestDate { get; set; }
    public Nullable<System.TimeSpan> TestTime { get; set; }
    public Nullable<short> TypeOfTest { get; set; }
    public string LinerMaterial { get; set; }
    public string ImpellerMaterial { get; set; }
    public string ImpellerType { get; set; }
    public Nullable<short> NumberOfVanes { get; set; }
    public string Drive { get; set; }
    public Nullable<double> DischargeDiameter { get; set; }
 
    public virtual ICollection<TestSampleDataDTO> TestSampleData { get; set; }
 
    public ReportGraph HeadGraph { get; set; }
    public ReportGraph EfficiencyGraph { get; set; }
    public ReportGraph PowerGraph { get; set; }
}

The Graph object and polynom-class looks like this:
public class ReportGraph
{
    public ReportPolynom Polynom { get; set; }
    public ReportAxis HorizontalAxis { get; set; }
    public ReportAxis VerticalAxis { get; set; }
}
 
public class ReportPolynom
{
    public ReportAxis VerticalAxis { get; set; }
    public double[] PolynomCoefficients { get; set; }
    public CurvePoint[] CalculatedPoints { get; set; }
 
    public int StartCalculationRange { get; set; }
    public int EndCalculationRange { get; set; }
 
    public CurvePoint[] MarkerPoints { get; set; }
}
 
public class ReportAxis
{
    public int MinValue { get; set; }
    public int MaxValue { get; set; }
    public string Label { get; set; }
    public string ValueStringformat { get; set; }
    public bool IsVisible { get; set; }
}

The property CalculatedPoints contains the points that I want to display in the graph. 
When I try to create a graph with the wizard and use that object I can't see the X and Y properties, just the property CalculatedPoints. I guess that is why I had such a hard time mapping them.

You can see what the data selection screen looks like here.

Is it possible to scope the datacontext of the graph to that property or any other work-around to use the property of my class as the source for the points in the graph? I want to use some other properties as well from that class to set the axis labels etc. so I need to be able to access the other objects/properties also from the graph.

BR,
Mats
0
Stef
Telerik team
answered on 13 Sep 2013, 04:43 PM
Hello Mats,

As suggested by my colleague, the recommended approach to create a Graph item definition is to use the designer, where you can use only the collection of data points as data source. Once you have created the definition, reuse the generated in the report's designer.cs file code and set the Graph properties based on your custom object.

For example take a look at the attached report definition where using custom object describing partially a Graph item we create such programmatically. For more details about creating chart programmatically take a look at the How to: Create Chart Programmatically help article.

I hope this helps.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Mats
Top achievements
Rank 1
answered on 16 Sep 2013, 06:15 AM
Hi, and thank you once again for a good example.

However I have a requirement that I'm not sure how to fullfill.

In this first report I will have to graphs, the first one will contain two series; Head and Efficiency. I'm not sure if that example would help me out with that scenario. 
I would need to set the datasource of the graph to an object that contains X and Y coordinates for both graphs. One possible solution for this report would be to use a new type that would contain the X and Y values for both series (like XHead, YHead, XEfficiency and YEfficiency). But I would run into problems later on since the next graph I'm creating will contain a user defined amount of series where the series will be loaded from the database. I would then need to loop over the defined polynoms and programatically add series at runtime. The only possible solution I see is to set the datasource to an object containing all the polynoms and set the grouping expression to point out a specific polynom in that class; =Fields(Polynom[0].CalculatedValues(?).X). But that doesn't seem to be possible.

Do you have a work around for that scenario? Creating a user defined amount of series at runtime?

BR,
Mats
0
Stef
Telerik team
answered on 19 Sep 2013, 10:56 AM
Hi Mats,

What I understand is you have custom ReportGraph object, representing a Graph item and providing information about the item's properties and DataSource.

Basically the Graph series items (DataPoints) are generated automatically based on the provided data. The only way to add graph series items is to prepare your data (Fields.xxx) in a way that the required data points will be generated by the graph processing engine. Following the Graph item's structure the ReportGraph object should return a single collection of points combining information about category, series belonging, values to be displayed. The rest are:
  • Settings on the series as markers, colors, data point labels;
  • Settings on the scales as minimum and maximum;

Adding new series - data records in your database - should not be a problem if you have a proper data organization and add a field to specify on what criteria will be created the series in the Graph item. Notice the current model cannot be used directly as it describes different axes, data points y values, data points labels as separate collections without being unified.

If you need further help, please open a support ticket and send us a sample project and test data illustrating the scenario.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Mats
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Mats
Top achievements
Rank 1
Stef
Telerik team
Share this question
or