|
Can gantt chart set the different color pattern? |
Posted by Eva on May-21-2019 17:01 |
|
Hi
I want to set gantt chart in different main status will have its main color.
And in different sub status will have its main status color but different pattern.
I made a sample like the attachment.
Can chartdirector do this?
Thanks!
|
Re: Can gantt chart set the different color pattern? |
Posted by Peter Kwan on May-22-2019 01:05 |
|
Hi Eva,
Yes. An example is at:
https://www.advsofteng.com/doc/cdcom.htm#colorgantt.htm
In the above example, the different bars have different solid colors. You can use pattern colors as well by creating those colors using BaseChart.patternColor. Basically, you can create a pattern color by providing an image or an array of colors as a bitmap pattern. The pattern color can then be used just like any other color.
The following is example that uses pattern color as the fill color of the title bar and as the fill color of an area chart.
https://www.advsofteng.com/doc/cdcom.htm#patternarea.htm
Hope this can help.
Regards
Peter Kwan |
Re: Can gantt chart set the different color pattern? |
Posted by Eva on May-22-2019 11:47 |
|
Hi, Peter
Thanks! It help a lot.
But I got some problem with using patternColor.
I don't really understand how to use it...
I use the code below now.
It works fine but I don't know to create another different pattern.
actualColor = c.patternColor(Array(&HFFFFFF, &HFFFFFF, &HFFFFFF, &HFF0000, _
&HFFFFFF, &HFFFFFF, &HFFFFFF, &HFF0000, &HFFFFFF, &HFFFFFF, &HFFFFFF, _
&HFF0000, &HFFFFFF, &HFFFFFF, &HFFFFFF, &HFF0000), 4)
Do you have some sample with patternColor?
Thanks. |
Re: Can gantt chart set the different color pattern? |
Posted by Peter Kwan on May-22-2019 23:06 |
|
Hi Eva,
I often used Excel to draw the pattern I wanted. I have attached a screen shot for your reference.
Then I found out the smallest repeating "tile". In the attached pattern, it is a 3 x 3 tile, and so the pattern is:
&H000000, &Hffffff, &Hffffff
&Hffffff, &H000000, &Hffffff
&Hffffff, &Hffffff, &H000000
The pattern color is then:
actualColor = c.patternColor(Array( _
&H000000, &Hffffff, &Hffffff, _
&Hffffff, &H000000, &Hffffff, _
&Hffffff, &Hffffff, &H000000 _
), 3)
For your information, your vertical line pattern currently uses a 4 x 4 tile. It can actually be simplified to a 4 x 1 tile, like:
actualColor = c.patternColor(Array(&HFFFFFF, &HFFFFFF, &HFFFFFF, &HFF0000), 4)
Hope this can help.
Regards
Peter Kwan
|
Re: Can gantt chart set the different color pattern? |
Posted by Eva on May-23-2019 09:33 |
|
Hi, Peter
I got it. Thanks a lot! |
Re: Can gantt chart set the different color pattern? |
Posted by Eva on Jun-04-2019 19:25 |
|
Hi Peter
I got another problem with using pattern color.
I want to define the data type mapping with pattern color so I wrote a function which input was data type and it will return the pattern color.
But I found that the function will return the same pattern color even if I input different data type.
Here is my function code:
Private Function getColor(DataType As Integer, iCnt As Integer) As Long
Dim c As XYChart
Dim cd As New ChartDirector.API
Set c = cd.XYChart(620, 280, &HCCFFCC, &H0, 1)
Dim M As Long
Dim B As Long
Dim strHex As String
Select Case DataType
Case "0"
strHex = Hex(65535)
Case "1"
strHex = Hex(49152)
Case "2"
strHex = Hex(255)
Case "10201"
strHex = Hex(9408511)
Case "3"
strHex = Hex(B)
End Select
If Len(strHex) < 6 Then
strHex = String(6 - Len(strHex), "0") & strHex
End If
B = RGB(228, 228, 228)
M = Val("&H" & Right$(strHex, 2) & Mid$(strHex, 3, 2) & Left$(strHex, 2))
Select Case iCnt
Case 1
getColor = c.patternColor(Array( _
M, B, M, B, M _
, B, M, B, M, B _
, M, B, M, B, M _
, B, M, B, M, B _
, M, B, M, B, M _
), 5)
Case 2
getColor = c.patternColor(Array( _
B, B, B, B, B, B, B, B _
, B, B, B, B, B, B, B, B _
, B, B, B, M, M, B, B, B _
, B, B, M, M, M, M, B, B _
, B, B, M, M, M, M, B, B _
, B, B, M, M, M, M, B, B _
, B, B, B, M, M, B, B, B _
, B, B, B, B, B, B, B, B _
, B, B, B, B, B, B, B, B _
), 9)
Case 3
getColor = c.patternColor(Array( _
B, B, B, M, B, B, B _
, B, B, M, M, M, B, B _
, B, M, M, M, M, M, B _
, M, M, M, M, M, M, M _
, B, M, M, M, M, M, B _
, B, B, M, M, M, B, B _
, B, B, B, M, B, B, B _
), 7)
End Select
End Function
Is anything I did wrong? |
Re: Can gantt chart set the different color pattern? |
Posted by Peter Kwan on Jun-05-2019 00:49 |
|
Hi Eva,
The pattern color is valid only for the chart that creates the pattern color. For example, when you use:
myColor = myChart.patternColor(....)
The color above is only valid for myChart. It is not valid for another chart.
For your case, the chart "c" is created inside getColor and stored in a local variable. So the pattern color is only valid for that "c". If you use it on another chart object, it would not work.
I suspect your intention is to create a pattern color to be used by another chart object. In this case, the function needs to be changed to:
Private Function getColor(c As XYChart, DataType As Integer, iCnt As Integer) As Long
Dim M As Long
Dim B As Long
Dim strHex As String
Select Case DataType
Case "0"
strHex = Hex(65535)
Case "1"
strHex = Hex(49152)
Case "2"
strHex = Hex(255)
Case "10201"
strHex = Hex(9408511)
Case "3"
strHex = Hex(B)
End Select
If Len(strHex) < 6 Then
strHex = String(6 - Len(strHex), "0") & strHex
End If
B = RGB(228, 228, 228)
M = Val("&H" & Right$(strHex, 2) & Mid$(strHex, 3, 2) & Left$(strHex, 2))
Select Case iCnt
Case 1
getColor = c.patternColor(Array( _
M, B, M, B, M _
, B, M, B, M, B _
, M, B, M, B, M _
, B, M, B, M, B _
, M, B, M, B, M _
), 5)
Case 2
getColor = c.patternColor(Array( _
B, B, B, B, B, B, B, B _
, B, B, B, B, B, B, B, B _
, B, B, B, M, M, B, B, B _
, B, B, M, M, M, M, B, B _
, B, B, M, M, M, M, B, B _
, B, B, M, M, M, M, B, B _
, B, B, B, M, M, B, B, B _
, B, B, B, B, B, B, B, B _
, B, B, B, B, B, B, B, B _
), 9)
Case 3
getColor = c.patternColor(Array( _
B, B, B, M, B, B, B _
, B, B, M, M, M, B, B _
, B, M, M, M, M, M, B _
, M, M, M, M, M, M, M _
, B, M, M, M, M, M, B _
, B, B, M, M, M, B, B _
, B, B, B, M, B, B, B _
), 7)
End Select
End Function
In the above, the parameter "c" is the chart the needs to use the pattern color.
Hope this can help.
Regards
Peter Kwan |
Re: Can gantt chart set the different color pattern? |
Posted by Eva on Jun-05-2019 15:19 |
|
Hi Peter,
Thanks a lot. It works fine now.
But I got one more question...
Is legend box can show on another container?
Because my chart has many kind of pattern color.
I want to set the legend box to show on a container that user can move it or set it invisible.
Is that possible to do it? |
Re: Can gantt chart set the different color pattern? |
Posted by Peter Kwan on Jun-05-2019 18:46 |
|
Hi Eva,
The only method is to create two charts. In one chart, there is the real chart but no legend box. In the second chart, there is just the legend box. You can create a chart with just a legend box by using empty arrays as the data, and to use a plot area 1 x 1 pixel in size and to put the plot area outside the chart (eg. in (x, y) = (-100, -100)). In this way, the overhead of the legend box only chart is minimal, as there is nothing to plot.
Regards
Peter Kwan |
|