[VB] Couleur des graphes MSCHART

Couleur des graphes MSCHART [VB] - Programmation

Marsh Posté le 02-05-2001 à 15:22:46    

Bonjour,  
Je voudrais changer les couleurs de mes graphes MSCHART dans mon source vb ( donc sans faire propriété du MSCHART dans l'éditeur VB ).
Si quelq'un sait comment k'on fait, je suis méga-prenneur! ;)
Merci!

Reply

Marsh Posté le 02-05-2001 à 15:22:46   

Reply

Marsh Posté le 03-05-2001 à 13:16:59    

up!

Reply

Marsh Posté le 03-05-2001 à 13:56:47    

Exemple pris dans MSDN :
 
Change the Color of MSChart Objects Using the CommonDialog Control
 
You may wish to allow the user to pick the colors assigned to chart elements (such as the color of series) using the CommonDialog control. In that case, you can use the following functions that mask the bytes returned by the CommonDialog control's Color property to return individual red, green, and blue values required by the Set method.
 
' Paste these functions into the Declarations section  
' of the Form or Code Module.
Public Function RedFromRGB(ByVal rgb As Long) _
   As Integer
   ' The ampersand after &HFF coerces the number as a  
   ' long, preventing Visual Basic from evaluating the  
   ' number as a negative value. The logical And is  
   ' used to return bit values.
   RedFromRGB = &HFF& And rgb
End Function
 
Public Function GreenFromRGB(ByVal rgb As Long) _
   As Integer
   ' The result of the And operation is divided by  
   ' 256, to return the value of the middle bytes.  
   ' Note the use of the Integer divisor.
   GreenFromRGB = (&HFF00& And rgb) \ 256
End Function
 
Public Function BlueFromRGB(ByVal rgb As Long) _
   As Integer
   ' This function works like the GreenFromRGB above,  
   ' except you don't need the ampersand. The  
   ' number is already a long. The result divided by  
   ' 65536 to obtain the highest bytes.
   BlueFromRGB = (&HFF0000 And rgb) \ 65536
End Function
 
Using the functions in the preceding examples, you can take the Long value returned by the CommonDialog object, and set the color of MSChart objects. The example below allows the user to change the color of a Series by double-clicking it:
 
Private Sub MSChart1_SeriesActivated(Series As _
   Integer, MouseFlags As Integer, Cancel As Integer)
   ' The CommonDialog control is named dlgChart.
   Dim red, green, blue As Integer
   With dlgChart ' CommonDialog object
      .ShowColor  
      red = RedFromRGB(.Color)
      green = GreenFromRGB(.Color)
      blue = BlueFromRGB(.Color)
   End With
 
   ' NOTE: Only the 2D and 3D line charts use the
   ' Pen object. All other types use the Brush.
 
   If MSChart1.chartType <> VtChChartType2dLine Or _
   MSChart1.chartType <> VtChChartType3dLine Then
      MSChart1.Plot.SeriesCollection(Series). _
         DataPoints(-1).Brush.FillColor. _
         Set red, green, blue
   Else
      MSChart1.Plot.SeriesCollection(Series).Pen. _
         VtColor.Set red, green, blue
   End If
End Sub

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed