Results 1 to 7 of 7

Thread: MSChart, arrrgh! Any help appreciated.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    9

    Unhappy MSChart, arrrgh! Any help appreciated.

    Hi, I hope you can help please.

    I have an MSChart control in my project that I use to display a single series of data. I am using a 2D Bar.

    I can successfully change the colour of the ALL bars at run-time but I am unable to change a single bar based on some criteria.

    All I need to do is change the colour of each bar based on the value of my data.

    I have searched all over for some help but all example code is based on multiple series data.

    Can anyone help please or i this impossible?

    If it is not possible, does anyone know of another control that would allow this?

    Many thanks,

    Bob

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Another frustrated individual trying to get MSChart to work. You said you searched all over. Did you try MSDN? That is the only place I've ever found anything pertienent information concerning this "sterling" control.

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Here is some code to change colors:
    Code:
    Dim x(2, 1) As Integer
    x(0, 0) = 1
    x(0, 1) = 2
    x(1, 0) = 3
    x(1, 1) = 2
    
    MSChart1.ChartData = x
    
    'Change background color
       With MSChart1.Plot
          ' Set the style to solid.
          .Wall.Brush.Style = VtBrushStyleSolid
          ' Set the color to yellow.
          .Wall.Brush.FillColor.Set 255, 255, 0
       End With
       
    'Change the color of the second series of data
       With MSChart1.Plot.SeriesCollection(2)
          .DataPoints(-1).Brush.FillColor.Set 0, 0, 255
       End With
    
    'Change the color of the first series of data
       With MSChart1.Plot.SeriesCollection(1)
          .DataPoints(-1).Brush.FillColor.Set 255, 255, 255
       End With
    Hope this helps

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    9

    Arrow Thanks but no cigar :)

    Thanks for your code Negative0

    Trouble is, as I say above, I only have one series of data. Your example works with two series of data.

    I wish to change the colour of each bar of that series at runtime.

    For example: A chart showing ping rates of an IP address would return values from say 10 - 1000. I show these values on my 2d bar chart in one series, each bar one after another.

    One set of data, blue bars for all values below 100 and red for all bars above 100.

    Any ideas?

    Thanks

    Originally posted by Negative0
    Here is some code to change colors:
    Code:
    Dim x(2, 1) As Integer
    x(0, 0) = 1
    x(0, 1) = 2
    x(1, 0) = 3
    x(1, 1) = 2
    
    MSChart1.ChartData = x
    
    'Change background color
       With MSChart1.Plot
          ' Set the style to solid.
          .Wall.Brush.Style = VtBrushStyleSolid
          ' Set the color to yellow.
          .Wall.Brush.FillColor.Set 255, 255, 0
       End With
       
    'Change the color of the second series of data
       With MSChart1.Plot.SeriesCollection(2)
          .DataPoints(-1).Brush.FillColor.Set 0, 0, 255
       End With
    
    'Change the color of the first series of data
       With MSChart1.Plot.SeriesCollection(1)
          .DataPoints(-1).Brush.FillColor.Set 255, 255, 255
       End With
    Hope this helps

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    This is for one series of data:

    If this doesnt work give me a better idea of what you are trying to do or maybe some source code

    Code:
    Dim x(8, 1) As Integer
    x(0, 0) = 1
    x(1, 0) = 2
    x(2, 0) = 3
    x(3, 0) = 2
    x(4, 0) = 2
    x(5, 0) = 4
    x(6, 0) = 5
    x(7, 0) = 6
    x(8, 0) = 7
    
    MSChart1.ChartData = x
    
    'Change background color
       With MSChart1.Plot
          ' Set the style to solid.
          .Wall.Brush.Style = VtBrushStyleSolid
          ' Set the color to green
          .Wall.Brush.FillColor.Set 0, 255, 0
       End With
       
    
    'Change the color of the first series of data
       With MSChart1.Plot.SeriesCollection(1)
          .DataPoints(-1).Brush.FillColor.Set 255, 255, 255
       End With
    Hope this helps,

    I just read your initial post, why dont you just make all of your pieces of data a different series, then you can control the color.
    Last edited by Negative0; Nov 21st, 2001 at 10:46 AM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    9
    Thanks again. I am unable to use different series for each data.

    To draw each colour as a different series, each of the series is given a space on the chart even if its not been set, this means the chart ends up with too many spaces where there is no values.
    e.g 10 series will show space on the chart for each of the ten series when I only want to draw the "bar" for which has a value.

    Perhaps I don't understand how to use series data in a bar chart? Am I able to get contiguous data shown on the chart?

    I attach an example chart with the sort of results I would like.

    The actual chart will show up to 5,000 bars at a time.

    As for the actual requirement, the best way to replicate my data is to randomly generate values between 0 and 500. Then dislplay those values in a bar chart, one after another, using different colours for values 0-50, 51-100, 101-200,201-500.

    Thankls again.

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Try This:

    Code:
    Dim x(0 To 0, 1 To 80) As Integer
    Dim j As Integer
    For j = 1 To 80
    x(0, j) = Rnd(Timer) * 500 + 1
    Next
    MSChart1.ChartData = x
    
       For j = 1 To 80
          If x(0, j) > 300 Then
             With MSChart1.Plot.SeriesCollection(j)
                .DataPoints(-1).Brush.FillColor.Set 0, 0, 255
             End With
          Else
             With MSChart1.Plot.SeriesCollection(j)
                .DataPoints(-1).Brush.FillColor.Set 255, 255, 255
             End With
          End If
       Next
    Hope this helps

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