User (Legacy) Posted March 23, 2004 Author Report Share Posted March 23, 2004 Hi, I am using the ChartFX Lite control in an application where I am pushing data into the chart as it arrives over a network. The application is reading an XML document (in this case it is stock quotes). I need to be able to do scrolling (a la ChartFX RealTime charts) when I reach a user-defined maximum number of datapoints, and I also need to add new series as new stock symbols are added (in other words, when the <symbol> element in the stock-quote XML has a new value). So, I have written a rather elaborate Plot() method, called by a "new-network-message" event handler, that just adds new values if we haven't reached the data point limit, and once we have, copies all the datapoints one slot to the left, adding the new value at the end. When I need to add a new series, because I can't use Chart.Hidden in the Lite control, I am clearing the data and starting over with one more series. It's all working fine, but the confounded SeriesLegend box simply won't display! I am walking through the list of series names after I call CloseData, and setting a string for each series. This is working fine, because I can read them back into a log file. Finally I call SerLegBox = true; But nothing happens! Here's my code (some of it may not make sense, but it all works except for the legend box): m_alSeries is just an array of little class objects (the class is called ChartSeries) that contain info about each series (name, index, etc.), and m_iNumDatapoints is the maximum number of datapoints the user wants to see at a time. If I have just added a new ChartSeries object to the list as of the last message, meaning I want to clear the chart and start again with one extra series, then I will have set the m_boolNewSeriesAdded flag to true before calling this method. void Plot() { if ( m_alSeries.Count < 1 ) { return; } // ok, we'll be plotting. int nPoints = 0; int nCurrPoints = chart.NValues; chart.SerLegBox = false; if ( m_boolNewSeriesAdded ) // meaning we have added a new series { chart.ClearData ( ClearDataFlag.AllData ); // reset the flag m_boolNewSeriesAdded = false; } // if we already have the maximum number of data points in the chart, then we will scroll off to the left. // Otherwise, we will just add new points. if ( nCurrPoints < m_iNumOfDatapoints ) // just adding new points here { nPoints = nCurrPoints + 1; } else { nPoints = m_iNumOfDatapoints; } chart.OpenData( COD.Values, m_alSeries.Count, nPoints ); // if NValues == 0 we have cleared the data due to the arrival of a new series, // or we are just getting started. if ( nCurrPoints == 0 ) { foreach ( ChartSeries cs in m_alSeries ) { chart.Value[ cs.SeriesIndex, 0 ] = cs.LastValue; } } else { // if NValues != 0, but is less than the maximum allowed, then we will just add the new points if ( nCurrPoints < m_iNumOfDatapoints ) { foreach ( ChartSeries cs in m_alSeries ) { // stick the new value at the end chart.Value[ cs.SeriesIndex, nPoints - 1 ] = cs.LastValue; } } else // chart is full, so we must scroll { foreach ( ChartSeries cs in m_alSeries ) { // first we must replot the existing data for ( int b = 1; b < ( nPoints ); b++ ) { chart.Value[ cs.SeriesIndex, b - 1 ] = chart.Value[ cs.SeriesIndex, b ]; } // now stick the new value at the end chart.Value[ cs.SeriesIndex, nPoints - 1 ] = cs.LastValue; } } } chart.CloseData ( COD.Values ); // now take care of the series legend box for ( int i = 0; i < m_alSeries.Count; i++ ) { chart.SerLeg[ i ] = ( (ChartSeries) m_alSeries[ i ] ).SeriesName; } chart.SerLegBox = true; } Link to comment Share on other sites More sharing options...
User (Legacy) Posted March 23, 2004 Report Share Posted March 23, 2004 Hi, I am using the ChartFX Lite control in an application where I am pushing data into the chart as it arrives over a network. The application is reading an XML document (in this case it is stock quotes). I need to be able to do scrolling (a la ChartFX RealTime charts) when I reach a user-defined maximum number of datapoints, and I also need to add new series as new stock symbols are added (in other words, when the <symbol> element in the stock-quote XML has a new value). So, I have written a rather elaborate Plot() method, called by a "new-network-message" event handler, that just adds new values if we haven't reached the data point limit, and once we have, copies all the datapoints one slot to the left, adding the new value at the end. When I need to add a new series, because I can't use Chart.Hidden in the Lite control, I am clearing the data and starting over with one more series. It's all working fine, but the confounded SeriesLegend box simply won't display! I am walking through the list of series names after I call CloseData, and setting a string for each series. This is working fine, because I can read them back into a log file. Finally I call SerLegBox = true; But nothing happens! Here's my code (some of it may not make sense, but it all works except for the legend box): m_alSeries is just an array of little class objects (the class is called ChartSeries) that contain info about each series (name, index, etc.), and m_iNumDatapoints is the maximum number of datapoints the user wants to see at a time. If I have just added a new ChartSeries object to the list as of the last message, meaning I want to clear the chart and start again with one extra series, then I will have set the m_boolNewSeriesAdded flag to true before calling this method. void Plot() { if ( m_alSeries.Count < 1 ) { return; } // ok, we'll be plotting. int nPoints = 0; int nCurrPoints = chart.NValues; chart.SerLegBox = false; if ( m_boolNewSeriesAdded ) // meaning we have added a new series { chart.ClearData ( ClearDataFlag.AllData ); // reset the flag m_boolNewSeriesAdded = false; } // if we already have the maximum number of data points in the chart, then we will scroll off to the left. // Otherwise, we will just add new points. if ( nCurrPoints < m_iNumOfDatapoints ) // just adding new points here { nPoints = nCurrPoints + 1; } else { nPoints = m_iNumOfDatapoints; } chart.OpenData( COD.Values, m_alSeries.Count, nPoints ); // if NValues == 0 we have cleared the data due to the arrival of a new series, // or we are just getting started. if ( nCurrPoints == 0 ) { foreach ( ChartSeries cs in m_alSeries ) { chart.Value[ cs.SeriesIndex, 0 ] = cs.LastValue; } } else { // if NValues != 0, but is less than the maximum allowed, then we will just add the new points if ( nCurrPoints < m_iNumOfDatapoints ) { foreach ( ChartSeries cs in m_alSeries ) { // stick the new value at the end chart.Value[ cs.SeriesIndex, nPoints - 1 ] = cs.LastValue; } } else // chart is full, so we must scroll { foreach ( ChartSeries cs in m_alSeries ) { // first we must replot the existing data for ( int b = 1; b < ( nPoints ); b++ ) { chart.Value[ cs.SeriesIndex, b - 1 ] = chart.Value[ cs.SeriesIndex, b ]; } // now stick the new value at the end chart.Value[ cs.SeriesIndex, nPoints - 1 ] = cs.LastValue; } } } chart.CloseData ( COD.Values ); // now take care of the series legend box for ( int i = 0; i < m_alSeries.Count; i++ ) { chart.SerLeg[ i ] = ( (ChartSeries) m_alSeries[ i ] ).SeriesName; } chart.SerLegBox = true; } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.