Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kentico 在条形图上创建趋势线_Kentico_Microsoft Chart Controls - Fatal编程技术网

Kentico 在条形图上创建趋势线

Kentico 在条形图上创建趋势线,kentico,microsoft-chart-controls,Kentico,Microsoft Chart Controls,我有一张肯蒂科报告区的条形图。我知道Kentico使用微软的图表控件。Microsoft图表控件具有在条形图上创建趋势线的功能,但我确实看到了如何利用Kentico Reporting上的趋势线的任何选项。 在报告工具上是否有任何选项可以获取此趋势线? 如果没有选择,有人能提出其他建议吗? 使用自定义模块是我最后一次尝试的选项。如果有人对此自定义模块有任何具体建议,也请分享。 我用的是Kentico7。 按照布伦德建议的方式工作,但是没有达到平均值 ChartArea area = graph

我有一张肯蒂科报告区的条形图。我知道Kentico使用微软的图表控件。Microsoft图表控件具有在条形图上创建趋势线的功能,但我确实看到了如何利用Kentico Reporting上的趋势线的任何选项。 在报告工具上是否有任何选项可以获取此趋势线? 如果没有选择,有人能提出其他建议吗? 使用自定义模块是我最后一次尝试的选项。如果有人对此自定义模块有任何具体建议,也请分享。 我用的是Kentico7。

按照布伦德建议的方式工作,但是没有达到平均值

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"]);
            }

我想,实际的问题是在我运行趋势线生成代码的地方没有
graph.ChartControl.Series[0]
。知道如何获取它吗?

报表图表通过\cmsModule\Reporting\Controls\ReportGraph.ascx呈现

您可以修改方法GetReportGraph,并根据某些条件(例如报告名称和图表名称)向图表控件ucChart添加其他设置(您必须硬编码)

请注意,您将需要直接修改Kentico代码,因此将更改保持在尽可能低的级别,我建议:

  • 将额外的设置代码放入外部类
  • 只需要一行额外的代码就可以调用它
  • 添加注释以将额外的代码行标记为自定义
e、 g:

  • 确保您注意到这些更改,以便将来升级

我以前修改过控件,您可以在启用订阅之前在
GetReportGraph()
方法中使用此代码

// apply the trendline
if (TrendValue > 0)
{
    int chartAreas = graph.ChartControl.ChartAreas.Count;
    if (chartAreas > 0)
    {
        ChartArea area = graph.ChartControl.ChartAreas[chartAreas - 1];
        StripLine line = new StripLine();
        line.IntervalOffset = TrendValue;
        line.BorderColor = System.Drawing.ColorTranslator.FromHtml(TrendColor);
        line.BackColor = System.Drawing.ColorTranslator.FromHtml(TrendColor);
        line.StripWidth = TrendLineWidth;
        line.ToolTip = TrendToolTip;
        line.Text = TrendText;
        line.TextLineAlignment = trendLineAlignment;
        line.TextOrientation = TextOrientation.Horizontal;
        line.TextAlignment = trendTextAlignment;
        area.AxisY.StripLines.Add(line);
    }
}
当然,您必须添加适当的属性,并使用此控件传递其余页面/控件的值

#region Trending
/// <summary>
/// Value for the single trendline for whole chart
/// </summary>
public int TrendValue
{
    get
    {
        return mTrendValue;
    }
    set
    {
        mTrendValue = value;
    }
}

/// <summary>
/// Color of the trend line in hex format (i.e. #0000FF)
/// </summary>
public string TrendColor
{
    get
    {
        return mTrendColor;
    }
    set
    {
        mTrendColor = value;
    }
}

/// <summary>
/// Tool tip of the trend line
/// </summary>
public string TrendToolTip
{
    get
    {
        return mTrendToolTip;
    }
    set
    {
        mTrendToolTip = value;
    }
}

/// <summary>
/// Text of the trend line
/// </summary>
public string TrendText
{
    get
    {
        return mTrendText;
    }
    set
    {
        mTrendText = value;
    }
}

/// <summary>
/// Trend line width
/// </summary>
public double TrendLineWidth
{
    get
    {
        return mTrendLineWidth;
    }
    set
    {
        mTrendLineWidth = value;
    }
}

string mTrendLineAlignment;
public string TrendLineAlignment
{
    get
    {
        return mTrendLineAlignment;
    }
    set
    {
        mTrendLineAlignment = value;
    }
}
private System.Drawing.StringAlignment trendLineAlignment
{
    get
    {
        switch (TrendLineAlignment)
        {
            case "center":
                return System.Drawing.StringAlignment.Center;
            case "near":
                return System.Drawing.StringAlignment.Near;
            case "far":
                return System.Drawing.StringAlignment.Far;
            default:
                return System.Drawing.StringAlignment.Near;
        }
    }
}

string mTrendTextAlignment;
public string TrendTextAlignment
{
    get
    {
        return mTrendTextAlignment;
    }
    set
    {
        mTrendTextAlignment = value;
    }
}
private System.Drawing.StringAlignment trendTextAlignment
{
    get
    {
        switch (TrendTextAlignment)
        {
            case "center":
                return System.Drawing.StringAlignment.Center;
            case "near":
                return System.Drawing.StringAlignment.Near;
            case "far":
                return System.Drawing.StringAlignment.Far;
            default:
                return System.Drawing.StringAlignment.Near;
        }
    }
}


#endregion
#区域趋势分析
/// 
///整个图表的单个趋势线的值
/// 
公共int趋势值
{
得到
{
返回MTR值;
}
设置
{
mTrendValue=值;
}
}
/// 
///十六进制格式的趋势线颜色(即#0000FF)
/// 
公共字符串颜色
{
得到
{
返回mTrendColor;
}
设置
{
mTrendColor=值;
}
}
/// 
///趋势线的工具提示
/// 
公共字符串工具提示
{
得到
{
返回工具提示;
}
设置
{
mTrendToolTip=值;
}
}
/// 
///趋势线的文本
/// 
公共字符串文本
{
得到
{
返回mTrendText;
}
设置
{
mTrendText=值;
}
}
/// 
///趋势线宽度
/// 
公共双趋势线宽度
{
得到
{
返回mTrendLineWidth;
}
设置
{
mTrendLineWidth=值;
}
}
字符串对齐;
公共字符串趋势线对齐
{
得到
{
返回mTrendLineAlignment;
}
设置
{
mTrendLineAlignment=值;
}
}
专用系统.Drawing.StringAlignment趋势线对齐
{
得到
{
开关(趋势线对齐)
{
案例“中心”:
返回系统.Drawing.StringAlignment.Center;
案例“近”:
返回系统.Drawing.StringAlignment.Near;
案例“far”:
返回系统.Drawing.StringAlignment.Far;
违约:
返回系统.Drawing.StringAlignment.Near;
}
}
}
字符串mTrendTextAlignment;
公共字符串趋势文本对齐
{
得到
{
返回mTrendTextAlignment;
}
设置
{
mTrendTextAlignment=值;
}
}
专用系统.Drawing.StringAlignment trendTextAlignment
{
得到
{
开关(趋势文本对齐)
{
案例“中心”:
返回系统.Drawing.StringAlignment.Center;
案例“近”:
返回系统.Drawing.StringAlignment.Near;
案例“far”:
返回系统.Drawing.StringAlignment.Far;
违约:
返回系统.Drawing.StringAlignment.Near;
}
}
}
#端区

对不起,我终于成功了,但这里的趋势值是多少?我使用的是line.IntervalOffset=graph.ChartControl.DataManipulator.Statistics.Mean(graph.ChartControl.Series[0].Name);它抛出了一个错误,因为它没有为points graph.ChartControl.Series[0]获取任何值。
IntervalOffset
属性是一个整数,似乎您正在获取一个字符串。所以,即使你的图表系列[0]被指定了一个名称,它也是一个无效的演员阵容。明白你的意思吗?!间隔偏移为od型双精度,平均返回双精度;问题出现在我运行graph.ChartControl.Series[0]时。‌​Name应该返回序列-但它没有-看起来数据点没有设置!!
#region Trending
/// <summary>
/// Value for the single trendline for whole chart
/// </summary>
public int TrendValue
{
    get
    {
        return mTrendValue;
    }
    set
    {
        mTrendValue = value;
    }
}

/// <summary>
/// Color of the trend line in hex format (i.e. #0000FF)
/// </summary>
public string TrendColor
{
    get
    {
        return mTrendColor;
    }
    set
    {
        mTrendColor = value;
    }
}

/// <summary>
/// Tool tip of the trend line
/// </summary>
public string TrendToolTip
{
    get
    {
        return mTrendToolTip;
    }
    set
    {
        mTrendToolTip = value;
    }
}

/// <summary>
/// Text of the trend line
/// </summary>
public string TrendText
{
    get
    {
        return mTrendText;
    }
    set
    {
        mTrendText = value;
    }
}

/// <summary>
/// Trend line width
/// </summary>
public double TrendLineWidth
{
    get
    {
        return mTrendLineWidth;
    }
    set
    {
        mTrendLineWidth = value;
    }
}

string mTrendLineAlignment;
public string TrendLineAlignment
{
    get
    {
        return mTrendLineAlignment;
    }
    set
    {
        mTrendLineAlignment = value;
    }
}
private System.Drawing.StringAlignment trendLineAlignment
{
    get
    {
        switch (TrendLineAlignment)
        {
            case "center":
                return System.Drawing.StringAlignment.Center;
            case "near":
                return System.Drawing.StringAlignment.Near;
            case "far":
                return System.Drawing.StringAlignment.Far;
            default:
                return System.Drawing.StringAlignment.Near;
        }
    }
}

string mTrendTextAlignment;
public string TrendTextAlignment
{
    get
    {
        return mTrendTextAlignment;
    }
    set
    {
        mTrendTextAlignment = value;
    }
}
private System.Drawing.StringAlignment trendTextAlignment
{
    get
    {
        switch (TrendTextAlignment)
        {
            case "center":
                return System.Drawing.StringAlignment.Center;
            case "near":
                return System.Drawing.StringAlignment.Near;
            case "far":
                return System.Drawing.StringAlignment.Far;
            default:
                return System.Drawing.StringAlignment.Near;
        }
    }
}


#endregion