Jump to content
Software FX Community

ChartFX won't plot


jconstam

Recommended Posts

I have been trying to get ChartFX to plot data acquired from an embedded device connected via a direct serial connection as a multi-series line graph.  I have verified that I am getting the proper data at expected intervals, however, ChartFX refuses to plot the data.  No error or exception is provided.  The graph simply does not appear to change.  I have tested ChartFX in a separate project and easily managed to get it to plot a sinusoid with data I provided it with.  Using the same code and copying the chart object to the project where ChartFX refused to plot didn't change anything.  The graph still didn't change.  This is the code I am using (C#, Visual Studio 2005):

ArrayList chartSeries = new ArrayList( );foreach ( ChartObject chartobj in chartObjects ){   //Acquire data   string shortName = chartobj.Name;   chart.SerLeg.Add( shortName );

  chartSeries.Add( chartobj.YValues );   chartSeries.Add( chartobj.XValues );}

SoftwareFX.ChartFX.Data.ListProvider newList = new SoftwareFX.ChartFX.Data.ListProvider( chartSeries );for ( int i = 0; i < newList.List.Count; i++ ){   if ( i % 2 == 0 )   {     chart.DataSourceSettings.DataType[ i ] = DataType.Value;   }   else   {     chart.DataSourceSettings.DataType[ i ] = DataType.XValue;   }}chart.Gallery = Gallery.Lines;chart.DataSource = newList;double percentSpace = 2.5;chart.AxisY.Max = ( ( 100 + percentSpace ) / 100 ) * this.getMaxYValue( );chart.AxisY.Min = Math.Min( this.getMinYValue( ) - 3, ( ( 100 - percentSpace ) / 100 ) * this.getMinYValue( ) );chart.Refresh( );

 

And here is the code that works perfectly fine in another project:

      ArrayList test1 = new ArrayList( );     ArrayList test2 = new ArrayList( );     ArrayList xVals = new ArrayList( );       int index;

      index = 0;       test1.Clear( );       test2.Clear( );       xVals.Clear( );       test1.Add( Math.Sin( 50 * index ) );       test2.Add( Math.Cos( 50 * ( index + ( Math.PI / 4 ) ) ) );       xVals.Add( index );       ArrayList array = new ArrayList( );       array.Add( test1 );       array.Add( xVals );       array.Add( test2 );       array.Add( xVals );       SoftwareFX.ChartFX.Data.ListProvider listProvider = new SoftwareFX.ChartFX.Data.ListProvider( array );       chart1.DataSourceSettings.DataType[ 0 ] = DataType.Value;       chart1.DataSourceSettings.DataType[ 1 ] = DataType.XValue;       chart1.DataSourceSettings.DataType[ 2 ] = DataType.Value;       chart1.DataSourceSettings.DataType[ 3 ] = DataType.XValue;       chart1.Gallery = Gallery.Lines;       chart1.DataSource = listProvider;       chart1.Refresh( );       for ( int i = 0; i < 100; i++ )       {         SoftwareFX.ChartFX.Data.ListProvider oldList = ( SoftwareFX.ChartFX.Data.ListProvider ) chart1.DataSource;         test1 = ( ArrayList ) oldList.List[ 0 ];         xVals = ( ArrayList ) oldList.List[ 1 ];         test2 = ( ArrayList ) oldList.List[ 2 ];         index++;         if ( test2.Count > 100 )         {           test1.RemoveAt( 0 );           test2.RemoveAt( 0 );         }         else         {           xVals.Add( index );         }         test1.Add( Math.Sin( 50 * index ) );         test2.Add( Math.Cos( 50 * ( index + ( Math.PI / 4 ) ) ) );         array.Clear( );         array.Add( test1 );         array.Add( xVals );         array.Add( test2 );         array.Add( xVals );         SoftwareFX.ChartFX.Data.ListProvider newList = new SoftwareFX.ChartFX.Data.ListProvider( array );         chart1.DataSourceSettings.DataType[ 0 ] = DataType.Value;         chart1.DataSourceSettings.DataType[ 1 ] = DataType.XValue;         chart1.DataSourceSettings.DataType[ 2 ] = DataType.Value;         chart1.DataSourceSettings.DataType[ 3 ] = DataType.XValue;         chart1.Gallery = Gallery.Lines;         chart1.DataSource = newList;         chart1.Refresh( );         Thread.Sleep( 40 );       }

Link to comment
Share on other sites

I took your code and put it in a brand new application. I implemented dummy values for X and Y and I obtain the right chart. So the problem must be in the data itself. Please post a complete running sample that reproduces the problem. Here is the code I tried:

public class ChartObject

{

  public double[] YValues {   get { return new double[] { 10,20,30,40,50 }; }

  }

  public DateTime[] XValues {   get { return new DateTime[] { new DateTime(2007,1,1),new DateTime(2007,1,2),new DateTime(2007,1,3),new DateTime(2007,1,4),new DateTime(2007,1,5) }; }

  }

  public string Name {   get { return "My Name"; }

  }

}

private void button1_Click(object sender, System.EventArgs e)

{

 Chart chart = chart1;  ChartObject[] chartObjects = new ChartObject[] { new ChartObject(),new ChartObject() };

  ArrayList chartSeries = new ArrayList( );  foreach ( ChartObject chartobj in chartObjects )

  {

  //Acquire data   string shortName = chartobj.Name;

  chart.SerLeg.Add( shortName );

  chartSeries.Add( chartobj.YValues );

  chartSeries.Add( chartobj.XValues );

  }

  SoftwareFX.ChartFX.Data.

ListProvider newList = new SoftwareFX.ChartFX.Data.ListProvider( chartSeries );  for ( int i = 0; i < newList.List.Count; i++ )

  {

  if ( i % 2 == 0 )

  {

  chart.DataSourceSettings.DataType[ i ] =
DataType.Value;

  }

  else

  {

  chart.DataSourceSettings.DataType[ i ] =
DataType.XValue;

  }

  }

  chart.Gallery =
Gallery.Lines;

  chart.DataSource = newList;

  double percentSpace = 2.5;

  //chart.AxisY.Max = ( ( 100 + percentSpace ) / 100 ) * this.getMaxYValue( );

  //chart.AxisY.Min = Math.Min( this.getMinYValue( ) - 3, ( ( 100 - percentSpace ) / 100 ) * this.getMinYValue( ) );

  chart.Refresh( );

}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...