|
bar colors not working |
Posted by Max on Feb-07-2024 01:25 |
|
Hi
I m not sure why my bar colors are black and not matching what is in the legend.
See attached.
Dim layer As BarLayer = c.addBarLayer(dataSeries, color, name)
layer.setXData(timeStamps)
Color is integer
|
Re: bar colors not working |
Posted by Peter Kwan on Feb-07-2024 01:43 |
|
Hi Max,
The bars have a black border by default. If the bars are too thin (eg. 1 pixel wide), you will only see the black border. To solve the problem, you can set the border color to be the same as the fill color:
layer.setBorderColor(Chart.SameAsMainColor);
Best Regards
Peter Kwan |
Re: bar colors not working |
Posted by Max on Feb-07-2024 03:09 |
|
Thank you Peter.
It worked.
Second I want to ask you that since I m using MultiChart, do you know how to add legends of all charts into single legend? |
Re: bar colors not working |
Posted by Peter Kwan on Feb-07-2024 13:26 |
|
Hi Max,
For automatic legend entries, each chart only includes its own content into the legend box, but you can use your own code to add extra entries into the legend box. The following is an example where all entries in the legend box are added with code.
https://www.advsofteng.com/doc/cdnet.htm#surfacelinezone.htm
The key APIs are LegendBox.addKey, LegendBox.addKey2 and LegendBox.addText.
https://www.advsofteng.com/doc/cdnet.htm#LegendBox.addKey.htm
https://www.advsofteng.com/doc/cdnet.htm#LegendBox.addKey2.htm
https://www.advsofteng.com/doc/cdnet.htm#LegendBox.addText.htm
Because ChartDirector supports CDML text, which can include symbols, so LegendBox.addText can be used to add legend entries too.
https://www.advsofteng.com/doc/cdnet.htm#cdml.htm
Another method to add a legend entry is to simply add an empty layer into the chart. For example, you can add a line layer with symbols to the chart using empty data arrays. In this case, nothing will be drawn but there would still be an legend entry.
Sometimes it is useful to disable automatic legend entries and add all entries with your own code. You can use Layer.setLegendOrder to disable automatic legend entries.
It is also possible to create a small empty chart (usually a pie chart object is used) with just a legend box, with all entries added with code. You can then put the legend box outside the original chart.
Best Regards
Peter Kwan |
Re: bar colors not working |
Posted by Max on Feb-07-2024 23:28 |
|
As each chart is separate chart in Multi chart, we need to combine all legends with the first legend, which is with first chart. Presently each chart is making its own legend but I want all to go to one single legend on top of first graph.
Dim b As LegendBox = c.addLegend(100, 0, False, "Arial", 9)
b.setAlignment(Chart.TopCenter)
b.setBackground(Chart.Transparent, ChartDirector.Chart.CColor(Drawing.Color.Black))
b.setLineStyleKey() |
Re: bar colors not working |
Posted by Peter Kwan on Feb-08-2024 17:11 |
|
Hi Max,
I have modified the original Real-Time MultiChart sample code to put for legend entries to the legend box of the top chart. I only add the legend box on the top chart, so the other charts cannot have legend entries. Instead, for the other charts, I use LegendBox.addKey2 to add legend entries to the legend box of the top chart.
https://www.advsofteng.com/doc/cdnet.htm#LegendBox.addKey2.htm
Below please find the modified code and the chart produced.
Best Regards
Peter Kwan
|
|