I'm trying to display a line chart in my report.
I have it kinda working but there is a big problem...
The report should house data regarding a thermal treatment of material that lasts several hours.
Ergo there is a lot of data to display...
During my last attempt at displaying the chart in the PDF file during processing memory usage went slowly up to my limit of 2GB and stayed there like if resources were not freed up after the fact.
Is there maybe a better solution?
Just to give an idea there are upwards of 5000 values to display... I know it's a giant number but the last library I used was able to do it with minimal effort... I'm probably doing something wrong myself...
4 Answers, 1 is accepted

public
Tuple<ChartSeriesCollection, ChartSeriesCollection> getLogValues(
string
startTime,
string
stopTime)
{
List<SqlParameter> parameters =
new
List<SqlParameter>();
parameters.Add(prepDatetime2Par(
"@Val1"
, startTime));
parameters.Add(prepDatetime2Par(
"@Val2"
, stopTime));
using
(DataTable dtResult = execQueryWithResult(subframe.getConnSqlLocal(), SELECT_LOGVALUES, parameters))
{
ChartSeriesCollection airTCs =
new
ChartSeriesCollection();
ChartSeriesCollection materialTCs =
new
ChartSeriesCollection();
foreach
(DataColumn column
in
dtResult.Columns)
{
if
(column.ColumnName.Contains(
"AIR"
))
{
ChartSeries airTCValues =
new
ChartSeries();
airTCValues.Appearance.LabelAppearance.Visible =
false
;
airTCValues.Name = column.ColumnName;
airTCValues.Type = ChartSeriesType.Line;
airTCValues.Appearance.LineSeriesAppearance.Color = System.Drawing.Color.BlueViolet;
foreach
(DataRow row
in
dtResult.Rows)
{
airTCValues.AddItem(Double.Parse(row[column.ColumnName].ToString()));
}
airTCs.Add(airTCValues);
}
if
(column.ColumnName.Contains(
"MAT"
))
{
ChartSeries matTCValues =
new
ChartSeries();
matTCValues.Appearance.LabelAppearance.Visible =
false
;
matTCValues.Name = column.ColumnName;
matTCValues.Type = ChartSeriesType.Line;
matTCValues.Appearance.LineSeriesAppearance.Color = System.Drawing.Color.BlueViolet;
foreach
(DataRow row
in
dtResult.Rows)
{
matTCValues.AddItem(Double.Parse(row[column.ColumnName].ToString()));
}
materialTCs.Add(matTCValues);
}
}
return
Tuple.Create(airTCs, materialTCs);
}
}


public
void
AddGraph(Tuple<ChartSeriesCollection, ChartSeriesCollection> data)
{
Chart treatGraph =
new
Chart();
treatGraph.Name =
"treatGraph"
;
treatGraph.ChartTitle.Visible =
false
;
treatGraph.Legend.Visible =
false
;
treatGraph.BitmapResolution = 96F;
treatGraph.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
treatGraph.Size =
new
SizeU(Unit.Cm(20.000d), Unit.Cm(7.000d));
treatGraph.Location =
new
PointU(Unit.Cm(0.000d), Unit.Cm(0.100d));
treatGraph.PlotArea.Appearance.FillStyle.FillType = Telerik.Reporting.Charting.Styles.FillType.Gradient;
treatGraph.PlotArea.Appearance.FillStyle.MainColor = System.Drawing.Color.FromArgb(65, 201, 254);
treatGraph.PlotArea.Appearance.FillStyle.SecondColor = System.Drawing.Color.FromArgb(0, 107, 186);
treatGraph.PlotArea.Appearance.Dimensions.AutoSize =
true
;
// Set text and line for X axis
treatGraph.PlotArea.XAxis.AxisLabel.TextBlock.Text =
"Date and Time"
;
treatGraph.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red;
treatGraph.PlotArea.XAxis.Appearance.Width = 3;
treatGraph.PlotArea.XAxis.Appearance.Color = System.Drawing.Color.Red;
treatGraph.PlotArea.XAxis.AutoScale =
true
;
treatGraph.PlotArea.XAxis.Visible = Telerik.Reporting.Charting.Styles.ChartAxisVisibility.False;
treatGraph.PlotArea.XAxis.MaxItemsCount = 20;
// Set text and line for Y axis
treatGraph.PlotArea.YAxis.AxisLabel.TextBlock.Text =
"°C"
;
treatGraph.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red;
treatGraph.PlotArea.YAxis.Appearance.Width = 3;
treatGraph.PlotArea.YAxis.Appearance.Color = System.Drawing.Color.Red;
treatGraph.PlotArea.YAxis.AutoScale =
true
;
treatGraph.PlotArea.YAxis.MinValue = 25;
treatGraph.PlotArea.YAxis.MaxValue = 125;
treatGraph.PlotArea.YAxis.MaxItemsCount = 10;
// Add the series to the chart, chart to page.
treatGraph.Series.AddRange(data.Item1.ToArray());
treatGraph.Series.AddRange(data.Item2.ToArray());
detailSection.Items.Add(treatGraph);
}
This is the method that is actually generating the chart in the report...
The graph seems to ignore all my instructions as you can see in the attached PNG of the graph resulting from this method...
I know that the graph type exists now but it's very confusing and this seems much easier to use...
Hello Fabio,
Based on the provided code, I see that you use a Chart item that was made obsolete in Q1 2013. I recommend switching to a Graph item and connect it to the data at design-time. Creating reports with charts programmatically is rather difficult task and it is always safer to use built-in chart wizards that allow connecting to the data at design-time and setting the necessary groupings for categories, series etc.
You can either supply the data you have through ObjectDataSource or set Graph.DataSource property at run-time and use a mock-up data (could be in CSV format) at design-time - Working With Data at Design Time.
Regards,
Katia
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.