C#使用timeXaxis表示图表时间与数据(超图:infragistics)

时间:2011-11-24 15:58:11

标签: c# infragistics

我想使用ultrachart,infragistics做一个具有数据时间功能的情节。

我找到了这个样本:  DataTable Recap = MarketData.Tables.Add(“Recap”);

        // 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);

如果我有数据与数据,它的工作正常,但我想要的是时间(dd / mm / yyy)vs(double)。 如果您有任何想法,请告诉我。

由于

1 个答案:

答案 0 :(得分:0)

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

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);