Home Forums WinForms controls Xceed Chart for WinForms Chart and multi data source

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

    Hi

    I have a list of dataview as the datasource of the chart.

    this is my code

    ‘bind data to the chart

    Dim arrCollumns As String() = {“Value”, “DateTime”} ‘first column is number the second is datetime. 
    ‘ disable automatic labels
    chart.Axis(StandardAxis.PrimaryX).ScaleMode = AxisScaleMode.DateTime
    chart.Axis(StandardAxis.PrimaryX).ValueFormatting.Format = ValueFormat.Date
    chart.Axis(StandardAxis.PrimaryX).StaggerTexts = True 

    For i As Integer = 0 To List.Count – 1
    Dim dv As DataView = List.Item(i).View
    Dim line As LineSeries = CType(chart.Series.Add(SeriesType.Line), LineSeries)
    Dim arrSeries As New DataSeriesCollection
    arrSeries.Add(line.Values)
    arrSeries.Add(line.Labels)
    arrSeries.FillFromDataView(dv, arrCollumns)
    Next

    Chrt.Refresh()

    The chart display correctly

    1.on the Axis I saw dates from 1899 to 1900 if I disable the automin\automax and set the  DateTimeScale.Max\Min the chart is disappear.

    2.Is there any way to give each line in the chart a different color automatically without set the LineBorder.Color property.

    3.In the mouse down event I can know the X,Y how can I know the data values in this location.

    10x Nadav

    Imported from legacy forums. Posted by nadav (had 11934 views)

    User (Old forums)
    Member
    Post count: 23064

    1- You need to set the line series to use the XValues :

            line.UseXValues = true;

    2- No.  The only solution I see is to use a random number and use it to generate a random color :

            Random random = new Random();

            line.LineBorder.Color =

    Color.FromArgb( random.Next() )

    3- Use the HitTest method :

            HitTestResult hit = chartControl1.HitTest( e.X, e.Y );

            LineSeries tempSerieHit = hit.Series as LineSeries;

            if( tempSerieHit != null )

            {

                int dataPoint = hit.DataPointIndex;

            }

    Note that a good source of code, in order to find out how to do different things with the Chart, is our Chart Explorer.  Go to the Start Menu -> All Programs -> Xceed Components -> Our components in action! -> Xceed Chart Explorer for .NET.

    For example, you can go to All Examples -> Interactivity -> Mouse Events.  You can look at the code by clicking on the “C# Code” tab.  You will also find the complete source code of the explorer here :

    Under XP :

        C:\Program Files\Xceed Components\Xceed Chart for .NET and ASP.NET <version>\Samples

    Under Vista :

        C:\Xceed Component Samples\Xceed Chart for .NET <version>\Samples under Vista.

    Imported from legacy forums. Posted by André (had 294 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi.

    Thanks for your answers.

    When I use the  line.UseXValues = true the drawing chart is empty.What can I do?

    10x Nadav

    Imported from legacy forums. Posted by nadav (had 335 views)

    User (Old forums)
    Member
    Post count: 23064

    You need to use the XValues series instead of the Label series when setting the DataSeriesCollection :

    arrSeries.Add(line.XValues) instead of arrSeries.Add(line.Labels)

    However, this will work only if the dates in the DB are of OADate type, because this is the only DateTime type accepted by the chart.  If this is not the case, you will need to feed the data manually to the chart, getting the data from the DB, then transforming each date value using the OADate() method on DateTime.

    Imported from legacy forums. Posted by André (had 290 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi.

    thanks for your replay but on the Axis I saw dates from 1899 to 1900 .

    ?

    Imported from legacy forums. Posted by nadav (had 218 views)

    User (Old forums)
    Member
    Post count: 23064

    Can you paste the code snippet you are now using, along with a sample of the values you use to feed the chart?

    Are you still binding the chart to the DB?  If so, what type is use for the date column?

     

    Imported from legacy forums. Posted by André (had 290 views)

    User (Old forums)
    Member
    Post count: 23064

    The type of the column is double.

    here is my code:

    Dim

    chart As Xceed.Chart.Core.Chart = Chrt.Charts(0)
    Try

    ‘bind data to the chart
    Dim arrCollumns As String() = {fldOMLogValue, fldOMLogDateTime & “Number”}

    ‘ disable automatic labels
    chart.Axis(StandardAxis.PrimaryX).ScaleMode = AxisScaleMode.DateTime
    chart.Axis(StandardAxis.PrimaryX).ValueFormatting.Format = ValueFormat.Date
    chart.Axis(StandardAxis.PrimaryX).StaggerTexts = True

     

    For i As Integer = 0 To List.Count – 1
    Dim dv As DataView = List.Item(i).View
    dv.RowFilter = IIF_Generic(btnIgnoreZeroValues.Checked, RowFilter, Nothing)
    Dim line As LineSeries = CType(chart.Series.Add(SeriesType.Line), LineSeries)
    Dim arrSeries As New DataSeriesCollection

    arrSeries.Add(line.Values)
    arrSeries.Add(line.XValues)
    arrSeries.FillFromDataView(dv, arrCollumns)
    line.LineBorder.Color = GetLineColor(i + 1)
    line.LineBorder.Width = 3
    line.Name = List(i).OMName & “( “ & List(i).ServerName & ” )”
    line.DataLabels.Mode = DataLabelsMode.None
    Next
    Chrt.Refresh()
    Catch ex As Exception
    AG.HandleException(ex)
    End Try

     

    I’ll try to send you a demo project.

    Thanks Nadav

    Imported from legacy forums. Posted by nadav (had 328 views)

    User (Old forums)
    Member
    Post count: 23064

    If you are saying that the date column data type in your DataView is a double, this will not work.  Again, the values used on this axis when the ScaleMode is set to DateTime mus be of OADate type.

    LineSeries

    line = ( LineSeries )chart.Series.Add( SeriesType.Line );

    line.UseXValues =

    true;

    chart.Axis( StandardAxis.PrimaryX ).ScaleMode = AxisScaleMode.DateTime;

    line.AddXY( 25, new DateTime( 2008, 1, 1 ).ToOADate() );

     

    Imported from legacy forums. Posted by André (had 789 views)

    User (Old forums)
    Member
    Post count: 23064

    1.The datatype of OAdate is double.

    2.I’m trying to avoid using the addXY I want to use the FillFromDataView.

    Imported from legacy forums. Posted by nadav (had 651 views)

    User (Old forums)
    Member
    Post count: 23064

    This should work, but the values in the date column must be proper double values. How did you build these values?  Do you have a few date values from your double column you could paste here? 

    Imported from legacy forums. Posted by André (had 489 views)

    User (Old forums)
    Member
    Post count: 23064

    Here are the values 

    Y      X 

    2       39441.5021875

    4        39441.6130439815

    3        39441.7710648148

    2        39474.724375

    1       39475.5376851852

    Tthanks Nadav

    Imported from legacy forums. Posted by nadav (had 524 views)

    User (Old forums)
    Member
    Post count: 23064

    These values work fine here in a DB.  I’m not sure what could be the problem.  Here is the code I’m using to do this :

    Chart chart =  chartControl1.Charts[ 0 ];

    LineSeries

    line = ( LineSeries )chart.Series.Add( SeriesType.Line );

    chart.Axis( StandardAxis.PrimaryX ).ScaleMode = AxisScaleMode.DateTime;

    chart.Axis(

    StandardAxis.PrimaryX ).ValueFormatting.Format = ValueFormat.Date;

    chart.Axis(

    StandardAxis.PrimaryX ).StaggerLevels = 3;

    chart.Axis(

    StandardAxis.PrimaryX ).StaggerTexts = true;

    line.UseXValues =

    true;

    DataSeriesCollection seriesCollection = line.GetDataSeries( DataSeriesMask.Values | DataSeriesMask.XValues, DataSeriesMask.None, false );

    string[] columnsCollection = { “EmployeeID”, “BirthOADate” };

    OleDbConnection myConnection = new OleDbConnection( @”PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ProgramData\Xceed Software\Sample Data\Northwind – Copy.mdb” );

    OleDbCommand myCommand = new OleDbCommand( “select * from Employees”, myConnection );

    myCommand.Connection.Open();

    OleDbDataReader

    myReader = myCommand.ExecuteReader( CommandBehavior.CloseConnection );

    seriesCollection.FillFromDataReader( myReader, columnsCollection ); 

     

    I suggest you try the same code to see if it works on your side.  If it does, then integrate line by line the other things you are setting in your current project, until you get the behavior where it does not work, so as to identify the source of the problem.

     

    Imported from legacy forums. Posted by André (had 1323 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks.

    I have some more questions.

    1.Is there any option in linelabels to avoid some of the values for example the values are 4,5,0,0,3,0,6,7,0 and I want to show only the labels only when the value > 0.(Ignore this question I use the subset)

    2.Is there any way to assign to the line datalabel into the Axis label ..

    3.I want to write the dates to the Axis  and ignore the data(usexvalues = false)

    Thanks Nadav.

    Imported from legacy forums. Posted by nadav (had 687 views)

    User (Old forums)
    Member
    Post count: 23064

    2- Don’t understand your question. 

    3- Simply use your DateTime values and add them to the Labels collection of the axis.

    e.g.:

    DateTime dateTime = DateTime.FromOADate( 39441.6130439815 );

    chart.Axis(

    StandardAxis.PrimaryX ).Labels.Add( dateTime.ToString() );

     

    Imported from legacy forums. Posted by André (had 880 views)

    User (Old forums)
    Member
    Post count: 23064

    What I can do in case I want to use the barseries the barseries inherits from series and he dosen’t support the usexvalues.

    Imported from legacy forums. Posted by nadav (had 777 views)

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