Home Forums WinForms controls Xceed Chart for WinForms Real Time Line Series Chart

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18858 |

    Hi,

    I have a prob in real time line series chart that I have to create dynamic lines in chaLines in that chart wll be added according to the no. of rows in datatable and also after click on start button,values wll be fetch at the particular interval given by the user for those all dynamic lines wll be added.

    I have prob at objTimer_tick event that I initialize objlineseries in LoadGraph function and again I have to add values in objTimer_tick event s o I cant get that object in that function and I have to again initialize it thats y new copy is created and I m getting error.

    I added the code like that

    void LoadGraph()
    {
    objChartControl.Settings.RenderDevice = RenderDevice.OpenGL;
    objChartControl.Background.FillEffect.SetSolidColor(Color.AliceBlue);

    ((Legend)objChartControl.Legends[0]).Mode = LegendMode.Automatic;

    objChart = objChartControl.Charts[0];

    objChart.View.SetPredefinedProjection(PredefinedProjection.Orthogonal);
    objChart.MarginMode = MarginMode.Stretch;
    objChart.Margins = new RectangleF(10, 10, 80, 80);
    objChart.Axis(StandardAxis.Depth).Visible = false;
    objChart.Axis(StandardAxis.PrimaryY).AxisStyle = AxisStyle.Line;
    objChart.Axis(StandardAxis.PrimaryY).MajorGridLine.Pattern = Xceed.Chart.GraphicsCore.LinePattern.Dot;

    objChart.Wall(ChartWallType.Left).Width = 0.0f;
    objChart.Wall(ChartWallType.Floor).Width = 0.0f;
    objChart.Wall(ChartWallType.Left).Visible = true;
    objChart.Axis(StandardAxis.PrimaryX).DimensionScale.AutoLabels = false;
    objChart.Axis(StandardAxis.PrimaryY).MajorGridLine.Color = Color.DarkSlateGray;
    objChart.Axis(StandardAxis.PrimaryX).DimensionScale.NumberOfDataPointsBetweenLabels = 5;
    objChart.Axis(StandardAxis.PrimaryX).DimensionScale.NumberOfDataPointsBetweenTicks = 5;

    objLineSeries = new LineSeries[InitialData.Rows.Count];

    for (int i = 0; i <= InitialData.Rows.Count – 1; i++)
    {
    objLineSeries[i] = (LineSeries)objChart.Series.Add(SeriesType.Line);
    objLineSeries[i].Name = InitialData.Rows[i][“GroupName”].ToString();
    objLineSeries[i].MultiLineMode = MultiLineMode.Series;
    objLineSeries[i].DataLabels.Mode = DataLabelsMode.Every;
    objLineSeries[i].Values.ValueFormatting.Format = ValueFormat.CustomNumber;
    objLineSeries[i].Values.ValueFormatting.CustomFormat = “0.0”;
    objLineSeries[i].LineBorder.Color = Color.DarkOrange;
    objLineSeries[i].LineBorder.Width = 2;
    objLineSeries[i].LineFillEffect.SetSolidColor(Color.DarkOrange);
    }
    }

    #region –> Adds Chart <–
    WindowsFormsHost objWindowsFormsHost = new WindowsFormsHost();
    objWindowsFormsHost.Child = objChartControl;
    objWindowsFormsHost.Margin = new Thickness(5);
    grdChart.Children.Add(objWindowsFormsHost);
    #endregion

    SetTimer();
    SetInterval(Convert.ToInt32(nmHour.GSMValue), Convert.ToInt32(nmMinute.GSMValue), Convert.ToInt32(nmSecond.GSMValue));
    objChartControl.Refresh();

    void SetTimer()
    {
    objTimer = new Timer();
    objTimer.Tick += new EventHandler(objTimer_Tick);
    objTimer.Start();
    }

    void objTimer_Tick(object sender, EventArgs e)
    {
    //objLineSeries = new LineSeries[InitialData.Rows.Count];

    for (int i = 0; i <= InitialData.Rows.Count – 1; i++)
    {
    objLineSeries[i].Values.Add(Convert.ToDouble(InitialData.Rows[i][SelectedChart]));
    }
    objChartControl.Refresh();
    }

    Imported from legacy forums. Posted by khushboo (had 2560 views)

    Xceed Support
    Member
    Post count: 5658

    Could you send the error (with the stack trace).

    Here is a snippet of code I used to test this behavior and I did not get any error.

    <code>
    public Form1()
    {
    InitializeComponent();
    m_RandomGenerator = new Random();
    DataFeedTimer = new Timer();
    //Setting the Tick each 1 second
    DataFeedTimer.Interval = 1000;
    DataFeedTimer.Tick += new EventHandler( DataFeedTimer_Tick );
    }

    private Xceed.Chart.Core.Chart m_Chart;
    public Random m_RandomGenerator;
    private System.Windows.Forms.Timer DataFeedTimer;
    private static int index = 0;
    private DataSet dataSet;

    private void Form1_Load( object sender, EventArgs e )
    {
    ChartLabel header = m_ChartControl.Labels.AddHeader( “Real Time – Add Line Every second” );
    header.TextProps.Backplane.Visible = false;
    header.TextProps.FillEffect.Color = Color.Navy;
    header.TextProps.Shadow.Type = ShadowType.Solid;
    header.TextProps.HorzAlign = HorzAlign.Left;
    header.TextProps.VertAlign = VertAlign.Top;
    header.HorizontalMargin = 2;
    header.VerticalMargin = 2;

    ( ( Xceed.Chart.Core.Legend )m_ChartControl.Legends[ 0 ] ).Mode = LegendMode.Disabled;

    m_Chart = m_ChartControl.Charts[ 0 ];

    InitDataSet();

    DataFeedTimer.Start();
    }

    private void InitDataSet()
    {
    dataSet = new DataSet();

    for( int j = 0; j < 20; j++ )
    {
    //Create a DataTable
    DataTable dt = new DataTable();
    DataColumn dcId = new DataColumn();
    dcId.ColumnName = “ComplexId”;
    dcId.DataType = System.Type.GetType( “System.Int64” );
    dt.Columns.Add( dcId );

    for( int i = 0; i < m_RandomGenerator.Next( 2, 25 ); i++ )
    {
    System.Data.DataRow row = dt.NewRow();
    row[ “ComplexId” ] = i * ( j + 1 );
    dt.Rows.Add( row );
    }

    dataSet.Tables.Add( dt );
    }
    }

    private void DataFeedTimer_Tick( object sender, System.EventArgs e )
    {
    //Adding a line a each Tick
    LineSeries m_Line = ( LineSeries )m_Chart.Series.Add( SeriesType.Line );
    m_Line.Name = “Realtime line ” + index.ToString();
    m_Line.DataLabels.Mode = DataLabelsMode.None;

    //Adding the number of point depending on the number of rows in the corresponding DataTable
    for( int i = 0; i < dataSet.Tables[ index ].Rows.Count; i++ )
    {
    m_Line.Values.Add( dataSet.Tables[ index ].Rows[ i ][ 0 ] );
    }

    index++;
    if( index >= dataSet.Tables.Count )
    DataFeedTimer.Stop();

    m_ChartControl.Refresh();
    }
    </code>

    Imported from legacy forums. Posted by CharlesB (had 3273 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.