首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将timeXaxis用于图表时间与数据的C# (ultrachart: infragistics )

将timeXaxis用于图表时间与数据的C# (ultrachart: infragistics )
EN

Stack Overflow用户
提问于 2011-11-24 23:58:11
回答 1查看 4.3K关注 0票数 0

我想用ultrachart,infragistics来做一个数据的时间函数的图。

我找到了这个示例: DataTable Recap = MarketData.Tables.Add("Recap");

代码语言:javascript
复制
        // on ajoute des column a recap ne pas oublier de typer les colonnes
        Recap.Columns.Add("Date", typeof(DateTime));
        Recap.Columns.Add("Move Ticker price", typeof(double));
        Recap.Columns.Add("Move Index price", typeof(double));
        Recap.Columns.Add("Alpha",typeof (double));


        // on remplie recap
        for (int i = 0; i < TickerPrice.Rows.Count; i++)
        {
            DataRow destRow = Recap.NewRow();
            destRow["Move Ticker price"] = TickerPrice.Rows[i]["CHG_PCT_1D"];
            destRow["Move Index price"] = IndexPrice.Rows[i]["CHG_PCT_1D"];
            destRow["Date"] = TickerPrice.Rows[i]["Date"];
            Recap.Rows.Add(destRow);
        }

        // calcul du alpha
        foreach (DataRow dr in Recap.Rows)
            dr["Alpha"] = ((double)dr["Move Index price"]) * 1.5 - (double)dr["Move Ticker price"];

        // remplir le feed alpha
        FeedAlpha.DataSource = Recap;


        // faire un plot 
        ChartPureAlpha.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.Composite;

        ChartArea myChartArea = new ChartArea();
        ChartPureAlpha.CompositeChart.ChartAreas.Add(myChartArea);

        // Defines axes
        AxisItem axisX = new AxisItem();
        axisX.DataType = Infragistics.UltraChart.Shared.Styles.AxisDataType.Numeric;
        axisX.Labels.ItemFormatString = "<DATA_VALUE:0.00>";
        axisX.SetLabelAxisType = SetLabelAxisType.ContinuousData;
        axisX.OrientationType = Infragistics.UltraChart.Shared.Styles.AxisNumber.X_Axis;
        axisX.RangeType = AxisRangeType.Custom;
        axisX.RangeMin = -1;
        axisX.RangeMax = 1;
        myChartArea.Axes.Add(axisX);


        AxisItem axisY = new AxisItem();
        axisY.DataType = Infragistics.UltraChart.Shared.Styles.AxisDataType.Numeric;
        axisY.Labels.ItemFormatString = "<DATA_VALUE:0.00>";
        axisY.Labels.HorizontalAlign = StringAlignment.Far;
        axisY.SetLabelAxisType = SetLabelAxisType.ContinuousData;
        axisY.OrientationType = Infragistics.UltraChart.Shared.Styles.AxisNumber.Y_Axis;
        axisY.RangeType = AxisRangeType.Custom;
        axisY.RangeMin = -1;
        axisY.RangeMax = 1;

        myChartArea.Axes.Add(axisY);


        // Create and add series
        XYSeries BPLseries = new XYSeries();
        BPLseries.Label = "Blood L";

        for (int i = 0; i < Recap.Rows.Count; i++)
            BPLseries.Points.Add(new XYDataPoint((double)(Recap.Rows[i][2]), (double)Recap.Rows[i][1], "", false));


        // Add a chartLayerAppearance
        ChartLayerAppearance myScatterLayer = new ChartLayerAppearance();
        myScatterLayer.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.ScatterChart;
        myScatterLayer.ChartArea = myChartArea;
        myScatterLayer.AxisX = axisX;
        myScatterLayer.AxisY = axisY;
        myScatterLayer.Series.Add(BPLseries);



        ScatterChartAppearance sca1 = new ScatterChartAppearance();
        sca1.ConnectWithLines = true;
        sca1.Icon = SymbolIcon.None;
        myScatterLayer.ChartTypeAppearance = sca1;



        ChartPureAlpha.Series.Add(BPLseries);
        ChartPureAlpha.CompositeChart.ChartLayers.Add(myScatterLayer);


        CompositeLegend myLegend = new CompositeLegend();
        myLegend.ChartLayers.Add(myScatterLayer);
        myLegend.Bounds = new Rectangle(88, 2, 11, 15);
        myLegend.BoundsMeasureType = MeasureType.Percentage;
        myLegend.PE.ElementType = PaintElementType.Gradient;
        myLegend.PE.FillGradientStyle = GradientStyle.ForwardDiagonal;
        myLegend.PE.Fill = Color.CornflowerBlue;
        myLegend.PE.FillStopColor = Color.Transparent;
        myLegend.Border.CornerRadius = 10;
        myLegend.Border.Thickness = 1;

        ChartPureAlpha.CompositeChart.Legends.Add(myLegend);

如果我有数据vs数据,它工作得很好,但我想要的是时间(dd/mm/yyy) vs (double)。如果你有什么想法,请告诉我。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2012-04-21 04:53:03

您可以使用以下代码来获取时间与数据图表:

代码语言:javascript
复制
using Infragistics.Win.UltraWinChart;
using Infragistics.UltraChart.Resources.Appearance;

DataTable dt = new DataTable();
dt.Columns.Add("Value", typeof(double));
dt.Columns.Add("Date", typeof(DateTime));
dt.Rows.Add(1.0, DateTime.Parse("04/20/2012"));
dt.Rows.Add(0.5, DateTime.Parse("04/21/2012"));
dt.Rows.Add(0.25, DateTime.Parse("04/22/2012"));
dt.Rows.Add(0.125, DateTime.Parse("04/23/2012"));
dt.Rows.Add(0.0625, DateTime.Parse("04/24/2012"));
dt.Rows.Add(0.03125, DateTime.Parse("04/25/2012"));
dt.Rows.Add(0.015625, DateTime.Parse("04/26/2012"));
dt.Rows.Add(0.0, DateTime.Parse("04/27/2012"));

NumericTimeSeries series = new NumericTimeSeries();
series.DataBind(dt, "Date", "Value");

UltraChart ultraChart = new UltraChart();
ultraChart.Data.SwapRowsAndColumns = true;
ultraChart.Dock = DockStyle.Fill;
ultraChart.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.LineChart;
ultraChart.DataSource = dt;

this.Controls.Add(ultraChart);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8259692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档