最近翻阅资料,找到 chart.DataManipulator.FinancialFormula()公式的使用,打开另一扇未曾了解的窗,供大家分享一下。

一 DataManipulator类

运行时,执行数据操作。此类是通过chart中DataManipulator属性对外公开的。

在C#中的继承关系如下:

System.Object

System.Web.UI.DataVisualization.Charting.DataFormula

System.Web.UI.DataVisualization.Charting.DataManipulator

《命名空间:System.Web.UI.DataVisualization.Charting》

《程序集:System.Web.DataVisualization(在 System.Web.DataVisualization.dll 中)》

在DataManipulator属性中囊括了很多数学计算方法(大多都是针对图表的数据序列展开的)以下是这样一个列子:

double result = Chart1.DataManipulator.Statistics.Mean("Series1");平均值函数

double result = Chart1.DataManipulator.Statistics.Median("Series1");中值函数

 StatisticFormula 类计算统计公式。

二、DataFormula.FinancialFormula 方法

使用指定的参数从公式模块调用方法。

重载此成员。有关此成员的完整信息(包括语法、用法和示例),请单击重载列表中的相应名称。

在这里特别讲到的是预测函数功能的实现情况。

预测公式尝试根据历史数据找出拟合度最佳的回归函数,然后根据最拟合的函数预测最可能的未来数据值。

Chart.DataManipulator.FinancialFormula(
    FinancialFormula.Forecasting,
    "RegressionType,Period,ApproxError,ForecastError",
    "Historical",
    "Forecast,UpperError,LowerError")

三 预测函数的语法分析说明

此公式采用四个可选参数。

RegressionType

回归类型。使用一个数字来指示特定次数的多元回归,或者使用以下值之一指定不同的回归类型:Linear、Exponential、Logarithmic、Power。默认值为 2,与指定 Linear 等效。

Period

预测时段。公式会预测此指定的未来天数内的数据变化。默认值为序列长度的一半。

ApproxError

是否输出近似误差。如果设置为 false,则输出误差序列不包含相应历史数据的数据。默认值为 true。

ForecastError

是否输出预测误差。如果设置为 false,并且 ApproxError 设置为 true,则输出误差序列将包含所有预测数据点的近似误差。默认值为 true。

输入值:

此公式采用一个输入 Y 值。

Historical:用于预测的历史数据。

输出值:

此公式输出三个 Y 值。

Forecast:预测测值。

UpperError:上限误差。

LowerError:下限误差。
下面的示例以 Series1 (Series1:Y) 作为输入,在 Series2 上输出预测值 (Series2:Y),在 Series3 上输出误差范围(Series3:Y、Series3:Y2)。该示例采用二次多元回归,预测期间为 40 天。
Chart1.DataManipulator.FinancialFormula (FinancialFormula.Forecasting, "2,40,true,true", "Series1:Y", "Series2:Y,Series3:Y,Series3:Y2");

在编程的过程中,注意原始历史数据的输入,要求X轴的间隔是一定的,否则影响数据的回归分析

四:以下是自己编写的线性回归预测方法的一个公用类

using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;
using System; namespace WindowsFormsApplication8
{
class RegressionModelClass
{
#region 字段
double[] sourceData_X = new double[4]; // 样本数据 X 轴坐标值
double[] sourceData_Y = new double[4]; // 样本数据 Y 轴坐标值 double[] predictData_Y = new double[8]; // 预测的未来数据的 Y 轴坐标值
int n = 4; // 样本数据的个数 // Chart
System.Windows.Forms.DataVisualization.Charting.Chart chart_temp = new System.Windows.Forms.DataVisualization.Charting.Chart(); #endregion /// <summary>
/// 构造函数
/// </summary>
public RegressionModelClass(double[] data_x, double[] data_y)
{
for (int i = 0; i < n;i++)
{
sourceData_X[i] = data_x[i];
sourceData_Y[i] = data_y[i];
} InitialChart(chart_temp, sourceData_X, sourceData_Y);
} // 初始化 Chart 控件
private void InitialChart(System.Windows.Forms.DataVisualization.Charting.Chart chart, double[] data_x, double[] data_y)
{
#region 1. Title 设置
Title title = new Title(); //* 实例化
title.Text = "信息预测";
//** 关联
chart.Titles.Add(title); //* 当使用这种重载方式时,可以将属性传递
#endregion #region 2. ChartArea 设置
ChartArea chartarea1 = new ChartArea(); //* 实例化
chartarea1.Name = "chartarea1"; //* ChartArea 的唯一名称
// 关联
chart.ChartAreas.Add(chartarea1); //重要//使用这种重载方法
#endregion #region 3. 坐标轴设置
#region 3.1 X轴
Axis axis_X = new Axis();
axis_X.IntervalType = DateTimeIntervalType.Days;
axis_X.Title = "时 间"; //* 轴的标题
// ** 关联
chart.ChartAreas[0].AxisX = axis_X;
chart.ChartAreas[0].AxisX.Enabled = AxisEnabled.True;
#endregion #region 3.2.1 深度 -- Y 轴
Axis axisY_depth = new Axis();
axisY_depth.Title = "深度";
axisY_depth.LineColor = Color.Black;
axisY_depth.ArrowStyle = AxisArrowStyle.None;
axisY_depth.TextOrientation = TextOrientation.Stacked;
axisY_depth.TitleFont = new Font("微软雅黑", 14F, FontStyle.Bold);
axisY_depth.TitleForeColor = Color.Black;
axisY_depth.TitleAlignment = StringAlignment.Far;
axisY_depth.IsLabelAutoFit = false; axisY_depth.IntervalType = DateTimeIntervalType.Number;
axisY_depth.IsStartedFromZero = false;
axisY_depth.Minimum = 0;
axisY_depth.Maximum = 10;
axisY_depth.IntervalAutoMode = IntervalAutoMode.FixedCount;
axisY_depth.InterlacedColor = Color.Red; // ** 关联
chart.ChartAreas[0].AxisY = axisY_depth;
chart.ChartAreas[0].AxisY.Enabled = AxisEnabled.True;
#endregion #endregion #region 4. Series 设置 Series series = new Series();
series.Name = "样本数据曲线";
series.ChartType = SeriesChartType.Line;
series.XAxisType = AxisType.Primary;
series.YAxisType = AxisType.Primary;
// important
series.XValueType = ChartValueType.DateTime;
series.YValueType = ChartValueType.Double;
series.Enabled = true; //关联
series.ChartArea = chart.ChartAreas[0].Name;
chart.Series.Clear();
chart.Series.Add(series); // 注意要使用这个重载方法,不应该使用 Add(string)重载方法
#endregion #region 5. Points 设置 // 清除所有数据点
chart.Series[0].Points.Clear(); // 添加数据点
int m = data_x.Length;
for (int i = 0; i < m; i++)
{
chart.Series[0].Points.AddXY(data_x[i], data_y[i]);
}
#endregion
} /// <summary>
/// 得到基于回归分析预测的数据
/// </summary>
///
public double[] GetPredictData()
{
Series trendSeries = new Series();
trendSeries.Name = "trend";
trendSeries.ChartType = SeriesChartType.Line; // 关联
trendSeries.ChartArea = chart_temp.ChartAreas[0].Name;
chart_temp.Series.Add(trendSeries); string typeRegression = "2";
// The number of days for Forecasting (备注:该数字对应的单位与X轴的数据间隔单位有关,并不一定是“天”)
string forecasting = "4";
string error = "false";
string forecastingError = "false";
string parameters = typeRegression + ',' + forecasting + ',' + error + ',' + forecastingError; chart_temp.DataManipulator.FinancialFormula(FinancialFormula.Forecasting, parameters, chart_temp.Series[0], chart_temp.Series["trend"]); for (int i = 0; i < 8; i++) // 共4个预测值
{
predictData_Y[i] = Math.Round(chart_temp.Series["trend"].Points[i].YValues[0], 5); // chart.Series["trend"]共8个数据点
} return predictData_Y;
}
}
}

C# chart.DataManipulator.FinancialFormula()公式的使用 线性回归预测方法的更多相关文章

  1. Tensorflow 线性回归预测房价实例

    在本节中将通过一个预测房屋价格的实例来讲解利用线性回归预测房屋价格,以及在tensorflow中如何实现 Tensorflow 线性回归预测房价实例 1.1. 准备工作 1.2. 归一化数据 1.3. ...

  2. MathType给公式加三角着重号的方法

    MathType是一款出色的数学公式编辑器,不仅可以兼容word,还与PPT也兼容.它也可以在PPT中编辑出非常漂亮的公式,再加上PPT本身所具有的动画.颜色.显示等功能,在演示数学公式时非常的精美. ...

  3. 机器学习01:使用scikit-learn的线性回归预测Google股票

    这是机器学习系列的第一篇文章. 本文将使用Python及scikit-learn的线性回归预测Google的股票走势.请千万别期望这个示例能够让你成为股票高手.下面按逐步介绍如何进行实践. 准备数据 ...

  4. winform Chart控件 获取鼠标处坐标值方法

    Chart控件本身功能强大,应用广泛,因此其属性.方法也很多.此处介绍在很多应用中需要查看鼠标位置处坐标值的一些方法 1,调用Chart事件  GetToolTip 利用ToolTipEventArg ...

  5. 公式编辑器MathType基本使用方法总结----应付本科毕业论文完全没问题啦^_^

    本人计算数学专业毕业,写毕业论文和外文翻译的时候会遇到大量公式需要编辑,而且学校一般都要求用word.但是Word自带的公式编辑器只支持一种字体,当公式中涉及到特殊字体就不太方便了.如果用Latex来 ...

  6. MATLAB实现多元线性回归预测

    一.简单的多元线性回归: data.txt ,230.1,37.8,69.2,22.1 ,44.5,39.3,45.1,10.4 ,17.2,45.9,69.3,9.3 ,151.5,41.3,58. ...

  7. 数值积分:基于牛顿-柯茨公式的定步长和自适应积分方法 [MATLAB]

    #先上代码后补笔记# #可以直接复制粘贴使用的MATLAB函数!# 1. 定步长牛顿-柯茨积分公式 function [ integration ] = CompoInt( func, left, r ...

  8. 线性回归预测PM2.5----台大李宏毅机器学习作业1(HW1)

    一.作业说明 给定训练集train.csv,要求根据前9个小时的空气监测情况预测第10个小时的PM2.5含量. 训练集介绍: (1)CSV文件,包含台湾丰原地区240天的气象观测资料(取每个月前20天 ...

  9. Python 实现多元线性回归预测

    一.二元输入特征线性回归 测试数据为:ex1data2.txt ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ...

随机推荐

  1. mysql语句求按字段分组后组数是多少

    select count(distinct ID) from table Thinkphp CURD写 $count = $model->where($where)->count('dis ...

  2. Java - 将 List 等分(最后一部分处理多余部分)

    背景 今天由于要使用多线程,所以事先需要确定启动线程个数.于是需要先将集合进行分配,确定线程的个数. 解决方案 首先是实现 public static <T> List<List&l ...

  3. 用IO字节流复制文件-CopyFileByIo

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...

  4. MyBatis单个参数的动态语句引用

    参考:http://blog.csdn.net/viviju1989/article/details/17071909 是当我们的参数为String时,在sql语句中#{name} 会去我们传进来的参 ...

  5. cobalt strike 第一节连接到团队的服务器

    介绍:Cobalt Strike 一款以metasploit为基础的GUI的框架式渗透工具,集成了端口转发.服务扫描,自动化溢出,多模式端口监听,win exe木马生成,win dll木马生成,jav ...

  6. WTL教程

    很不错的教程 http://www.yakergong.net/wtl/

  7. ARM汇编中值滤波实验

    其实就是 汇编的排序然后选出中位数 排序写的是最直接的冒泡排序,因为简单. 相应的C代码 r2=r0; while(r1<r0){ r1++; r2=r2-; r3=; while(r3< ...

  8. mybatis 传入集合参数遍历 查询总结

    出自:http://blog.csdn.net/u013628152/article/details/51184641 1. findByIds(List ids) 如果参数的类型是List, 则在使 ...

  9. jquery排序与动态添加option以及属性

    function getOrgansid() { url="<%=basePath%>/rest/bsc/organ/selectOrganSidAllList"; $ ...

  10. Eclipse修改tomcat初始分配空间参数

    正常启动tomcat后,运行报java.lang.OutOfMemoryError: PermGen space,查阅是tomcat内存溢出,也就是分配给tomcat的永久内存小了点 在Eclipse ...