Results 1 to 12 of 12

Thread: [RESOLVED] Is there an override/workaround for this?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    58

    Resolved [RESOLVED] Is there an override/workaround for this?

    The ms chart control is quite fussy. If I use this code in a loop where the data is created :

    Code:
     Form1.Chart1.Series(count).Points.AddXY(x, y)
    *
    It returns this, which is great.

    Name:  Good example.jpg
Views: 193
Size:  18.7 KB

    However, I need the data to be in a datatable, and the chart to be created from the data in the table. Rather than using databind, because it gives terrible values for the axes, I tried this:

    Code:
            For Each row As DataRow In ARpassover_table.Rows
                Chart1.Series(count).Points.AddXY(row.Item(0), row.Item(1))
            Next row
    The aim was to create the same chart as above. Unfortunately the result was this :

    Name:  Bad example.jpg
Views: 182
Size:  18.1 KB

    Whhhhhhhhyyyyyyyy! (The same data was used)

    Any ideas on how to get it looking like the first example, using data from a datatable?

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Is there an override/workaround for this?

    you can set the min, max values and label format for the x axis when it is data bound

    Me.Chart1.ChartAreas(0).AxisX.Minimum = 0
    Me.Chart1.ChartAreas(0).AxisX.Maximum = 30
    Me.Chart1.ChartAreas(0).AxisX.LabelStyle.Format = "#.#"

    The chart is very flexible but getting to the proper properties can be a bit of a challenge
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    58

    Re: Is there an override/workaround for this?

    Thanks for quick reply,

    No luck, for some reason, the X- axis becomes impervious to all simple editing using your examples resulted in this:

    Name:  your examples.jpg
Views: 158
Size:  17.8 KB

    I believe that the X axis is showing the first 30 values of the datatable. I know that it works as expected with Y axis, but with the x axis it decides doing unhelpful stuff would be better

  4. #4
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Is there an override/workaround for this?

    I set the format and scale on the x axis regularly with out issue.... I would put a break point of the chart.DataBind line and double check your variables before it runs just to make sure.
    Unfortunately there is not a whole lot out there about ms chart. I had to learn most of what I know about it by trial and error.
    GL
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    58

    Re: Is there an override/workaround for this?

    There is no chart.databind, this is all done by looping through a datatable using:

    Code:
     For Each row As DataRow In ARpassover_table.Rows
                Chart1.Series(count).Points.AddXY(row.Item(0), row.Item(1))
            Next row

  6. #6
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Is there an override/workaround for this?

    o....
    you should look into binding the table to the chart. It make life a bit easier and may be the root of your problem
    To bind it set the Series.DataSource.XValueMember and YValueMember properties to the column names of datatable and call the chart.DataBind method...

    Name:  Untitled.png
Views: 168
Size:  22.7 KB
    Attached Images Attached Images  
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    58

    Re: Is there an override/workaround for this?

    Using databind warps the shape of the graph, because more of the data is in the 2nd half of the data. Look at the first post, i'm trying to recreate the first image, but using data that is already in a table

  8. #8
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Is there an override/workaround for this?

    yea, sorry, I didn't read your first post correctly
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Is there an override/workaround for this?

    All things being equal ...

    Chart1.Series(count).Points.AddXY(x, y) & Chart1.Series(count).Points.AddXY(row.Item(0), row.Item(1))

    ... are exactly the same command. So, despite your protestations, all things clearly are not equal. When you say the data series are identical, is that actually true? Are they the exact same type, do they have the same precision, do both have the same starting point? If the data points are literally identical then there must be something in the set-up of the chart itself that is not identical in both cases. It simply cannot be the case that using values from a datatable is in itself the cause of the difference.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    58

    Re: Is there an override/workaround for this?

    Yes, they are both identical. When I loop through the table trying to add them to the chart, the chart acts as if it is databound to the table. I don't really know why, but data binding causes all sorts of problems so I'm trying to avoid it. Without being databound, the graph looks like picture #1. When it's looped through the table to add, it behaves as if it is databound, and ruins the axes and the shape of the graph.

  11. #11
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Is there an override/workaround for this?

    I still don't do Data, so I can't explain why the effect you are seeing happens, buuuut.....

    When using your DataTable, try casting your data to the appropriate Type:
    Code:
    For Each row As DataRow In ARpassover_table.Rows
        
        Dim x As Double = CDbl(row.Item(0))
        Dim y As Double = CDbl(row.Item(1))
    
        Chart1.Series(0).Points.AddXY(x, y)
    
    Next row
    Or maybe create a strongly Typed DataTable:
    Code:
    ARpassover_table = New DataTable
    ARpassover_table.Columns.Add("X", GetType(Double))
    ARpassover_table.Columns.Add("Y", GetType(Double))
    '
    ' Fill table with data
    '
    and:
    Code:
    For Each row As DataRow In ARpassover_table.Rows
        Chart1.Series(0).Points.AddXY(row.Item("X"), row.Item("Y"))
    Next row
    Maybe databinding to the Chart will work with a strongly Typed DataTable? I don't know; I don't do Data!

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    58

    Re: Is there an override/workaround for this?

    You... hero. I don't know why it works, but it does.

    Casting the data to an appropriate type works exactly as I wanted it to, fantastic!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width