C # с использованием timeXaxis для графика время против данных (Ultrachart: Infragistics) - PullRequest
0 голосов
/ 24 ноября 2011

Я хотел бы сделать график с функцией времени данных с помощью ультрачарта, 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);

Работает нормально, если у меня есть данные против данных, но мне нужно время (дд / мм / ггг) против (двойное). Пожалуйста, дайте мне знать, если у вас есть идеи.

Спасибо

1 Ответ

0 голосов
/ 21 апреля 2012

Вы можете использовать следующий код для получения графика времени против данных:

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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...