我在 Kentico 报告部分有一个条形图。我知道 Kentico 使用 Microsoft 图表控件。 Microsoft 图表控件能够在条形图上创建趋势线 - 但我确实看到了如何在 Kentico Reporting 上利用这些选项的任何选项。 报告工具是否有任何选项可以获取这条趋势线? 如果没有选择,有人可以提出其他建议吗? 使用自定义模块是我尝试的最后一个选择。如果有人对此自定义模块有任何具体建议,也请分享。 我正在使用 Kentico 7。
按照布伦德建议的方式工作,但平均值没有出现
ChartArea area = graph.ChartControl.ChartAreas[chartAreas - 1];
StripLine line = new StripLine();
// Set threshold line so that it is only shown once
line.Interval = 0;
// Set the threshold line to be drawn at the calculated mean of the first series
line.IntervalOffset = graph.ChartControl.DataManipulator.Statistics.Mean(graph.ChartControl.Series[0].Name);
line.BackColor = System.Drawing.Color.DarkGreen;
line.StripWidth = 0.25;
// Set text properties for the threshold line
//line.Text = "Mean";
line.ForeColor = System.Drawing.Color.Black;
// Add strip line to the chart
area.AxisY.StripLines.Add(line);
此外,对于其他趋势线,我使用以下代码,再次没有运气,因为看起来数据点没有在我的代码运行点设置:
int chartAreas = graph.ChartControl.ChartAreas.Count;
if (chartAreas > 0)
{
graph.ChartControl.Series.Add("TrendLine");
graph.ChartControl.Series["TrendLine"].ChartType = SeriesChartType.Line;
graph.ChartControl.Series["TrendLine"].BorderWidth = 3;
graph.ChartControl.Series["TrendLine"].Color = System.Drawing.Color.Red;
// Line of best fit is linear
string typeRegression = "Linear";//"Exponential";//
// The number of days for Forecasting
string forecasting = "1";
// Show Error as a range chart.
string error = "false";
// Show Forecasting Error as a range chart.
string forecastingError = "false";
// Formula parameters
string parameters = typeRegression + ',' + forecasting + ',' + error + ',' + forecastingError;
graph.ChartControl.Series[0].Sort(PointSortOrder.Ascending, "X");
// Create Forecasting Series.
graph.ChartControl.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, graph.ChartControl.Series[0], graph.ChartControl.Series["TrendLine"]);
}
我猜,实际问题是在我运行 TrendLine 生成代码的地方没有 graph.ChartControl.Series[0]
。知道如何获得它吗?
最佳答案
报表图表通过\CMSModules\Reporting\Controls\ReportGraph.ascx呈现
您可以修改 GetReportGraph 方法,并根据某些条件向图表控件 ucChart 添加额外的设置,例如报告名称和图表名称(您必须对其进行硬编码)
请注意,您将需要直接修改 Kentico 代码,因此我建议将更改保持在尽可能低的水平:
- 将额外的设置代码放入外部类
- 只需额外一行代码即可调用它
- 添加注释以将额外的代码行标记为自定义
例如:
/* YourCompany */
MyChartExtender.ExtendChart(ucChart, ...);
/* YourCompany end */
- 请务必记下这些更改,以便将来升级
关于kentico - 在条形图上创建趋势线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34387003/