|
circles Legend |
Posted by Vladimirt on Mar-12-2024 09:03 |
|
My legend displays colored squares. How can I change the code so that there are circles instead of squares?
b.setText("<*block,valign=top*>{={sector}+1}.<*advanceTo=22*><*block,width=430*>{label}<*/*><*block,width=50,halign=right*>{percent}<*/*>%") |
Re: circles Legend |
Posted by Peter Kwan on Mar-13-2024 04:20 |
|
Hi Vladimirt,
You may try to include a circle shape of the correct color in the legend text using CDML. To do this, you would need to create an extra field that contains the correct color in the correct format (hex format). The original square icon can be made invisible by setting its size to 1, and then cover it with the new circle shape.
The exact code depends on your programming language. The following is in C#:
// Reduce the size of the square icon to 1
b.setKeySize(1);
// Add an extra field with the colors in hex
c.addExtraField(Array.ConvertAll(colors, x => x.ToString("X")));
// The icon text includes a circle shape with the color set to the extra field.
// The negative margin is to move the circle shape and text leftwards to cover up the
// small square icon.
b.setText("<*block,valign=top,margin=-12 0*><*img=@circle,width=10,height=10,color={field0}*> " +
"{={sector}+1}, <*block,width=120*>{label}<*/*><*block,width=40,halign=right*>{percent}<*/*>%");
Best Regards
Peter Kwan
|
Re: circles Legend |
Posted by Vladimirt on Mar-13-2024 06:43 |
|
Please show me the full code of your pie chart |
Re: circles Legend |
Posted by Vladimirt on Mar-13-2024 07:22 |
|
Please VB.NET |
Re: circles Legend |
Posted by Peter Kwan on Mar-13-2024 13:43 |
|
Hi Vladimirt,
Atttached please find the VB.NET version of the code. It is based on the original "Pie Chart with Legend (2)". I added some code to change the icons to circles. As I do not know what framework you are using, I just random choose the ASP.NET Web Forms framework:
https://www.advsofteng.com/doc/cdnet.htm#legendpie2.htm
The code in other frameworks should be almost exactly the same. Just change the WebChartViewer to the type of viewer you are using.
Best Regards
Peter Kwan
|
Re: circles Legend |
Posted by Vladimirt on Mar-13-2024 15:34 |
|
Where's the script?
<script type="text/javascript" src="cdjcv.js"></script>
Doesn't work without it |
Re: circles Legend |
Posted by Vladimirt on Mar-13-2024 15:40 |
|
Screen |
Re: circles Legend |
Posted by Vladimirt on Mar-13-2024 17:40 |
|
I really have a WEB application on VB.NET(aspx)
Where is the function that is being referenced Function(x) ? |
Re: circles Legend |
Posted by Peter Kwan on Mar-13-2024 18:11 |
|
Hi Vladimirt,
Function(x) is to define a lambda function in VB.NET syntax. See:
https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions
If your system thinks that it is an error, may be it is using an older version of VB.NET. As far as I know, you need VB.NET that comes with Visual Studio 2008 or later.
If your system does not support lambda expression, you can use the traditional method to generate an array that contains the colors in hexadecimal format.
' *** Lambda expression not support ***
' Add an extra field with the colors in hex
'c.addExtraField(Array.ConvertAll(colors, Function(x) x.ToString("X")))
'
Dim hexColors(UBound(colors)) As String
For i As Integer = 0 to Ubound(colors)
hexColors(i) = colors(i).ToString("X")
Next
c.addExtraField(hexColors)
Best Regards
Peter Kwan |
Re: circles Legend |
Posted by Peter Kwan on Mar-13-2024 17:54 |
|
Hi Vladimirt,
The cdjcv.js is not necessary for the code. The code should run normally with or without the cdjcv.js. If you think it is causing error, simple delete the <script> line that loads the "cdjcv.js" in the code.
For your information, the cdjcv.js is included in the ASP.NET Web Forms sample code that comes with the ChartDirector download. It is in "ChartDirector/NetWebCharts/NetWebCharts/VBNetASP". It is used in some of the sample code, but not the legendbox2.aspx.
Regards
Peter Kwan |
Re: circles Legend |
Posted by Vladimirt on Mar-13-2024 20:00 |
|
I still don't see the circles in the legend.
Dim colors() As Integer = {&H66aaee, &Heebb22, &Hbbbbbb, &H8844ff, &Hdd2222, &H009900}
Dim hexColors(5) As String
For i As Integer = 0 to 5
hexColors(i) = colors(i).ToString("X")
Next
c.addExtraField(hexColors)
b.setText("<*block,valign=top*><*img=@circle,width=20,height=20,color={field0}*> " & "{={sector}+1}. <*block,width=120*>{label}<*/*><*block,width=40,halign=right*>{percent}<*/*>%") |
Re: circles Legend |
Posted by Peter Kwan on Mar-13-2024 21:14 |
|
Hi Vladimirt,
I have attached the complete code. Please test it without any modification to see it works in your machine.
The CDML used to draw the circle symbol should work for all ChartDirector releases after June 2012. In the code I attached, I have modified it to add the version number in the chart title. If it still does not work, please let me know the version number shown in the chart title.
Regards
Peter Kwan
|
Re: circles Legend |
Posted by Vladimirt on Mar-14-2024 07:04 |
|
5000004 |
Re: circles Legend |
Posted by Peter Kwan on Mar-14-2024 14:51 |
|
Hi Vladimirt,
Your ChartDirector version is 5.04. The CDML symbols feature is introduced in ChartDirector 5.1. See:
https://www.advsofteng.com/release51.html
Upgrading from 5.04 to 5.1 is free of charge. You can download ChartDirector 5.1 from:
https://www.advsofteng.com/download_v511.html
You just need to replace your existing "netchartdir.dll" with the one included in the 5.1 download and it should work.
Best Regards
Peter Kwan |
Re: circles Legend |
Posted by Vladimirt on Mar-14-2024 20:54 |
|
Thank you very much for your help, although it was not possible to completely hide the squares, so I had to install
b.setMargin(-20, 16, 16, 14) to make the squares go left outside the legend.
Here is the result: http://eao.myasp.ru/default.aspx |
|