|
Image in CDML table |
Posted by Revathi on Feb-26-2015 14:53 |
|
Hi,
How do I set an image before the text in each row of a CDML table. I tried the following
but doesn't work.
folderTable.setText(0, i,"<*block,valign=absmiddle*>
<*img="+Disk_Monitor.Properties.Resources.folder_15x13 +"*> <*/*> "+"
<*block,valign=absmiddle,width=" + getRelativeWidth(140) + ",truncate=1*>
<*font,color=" + (Chart.DataColor + i - 1).ToString("X8") +
"*>\\x25A0<*/font*> " + folderDataObj.FOLDERINFO_FOLDERNAMES[i - 1] + "<*/*>");
Kindly guide me on which method should be used.
Thanks & Regards,
Revathi |
Re: Image in CDML table |
Posted by Peter Kwan on Feb-27-2015 02:58 |
|
Hi Revathi,
Your code looks fine to me. Would you mind to clarify what is the issue? Is it that the text
and colors and bullets displays normally but there is no image?
From your previous posts, I assume you are writing a Windows Forms application (not a web
application). If everything is normal except the image, I suspect there is some issue in the
image path. Is it possible to perform a test that use a hard coded absolute image path? For
example, you may copy the file "sun.png" (this is an image included in the ChartDirector
sample code) to the root of your "c:" hard disk, the modify your code to:
folderTable.setText(0, i,"<*block,valign=absmiddle*>
<*img="+"c:\\\\sun.png"+"*> <*/*> "+"
<*block,valign=absmiddle,width=" + getRelativeWidth(140) + ",truncate=1*>
<*font,color=" + (Chart.DataColor + i - 1).ToString("X8") +
"*>\\x25A0<*/font*> " + folderDataObj.FOLDERINFO_FOLDERNAMES[i - 1] + "<*/*>");
In the above code, if the "sun.png" is displayed normally, then this confirms your code is
correct. In this case, you may try to test with your actual path hard coded to determine
the cause of the problem. You may try to test using an absolute path instead of a relative
path. (In many cases, the relative path does not work because of the incorrect assumption
of which directory it is relative to.)
Regards
Peter Kwan |
Re: Image in CDML table |
Posted by Revathi on Feb-27-2015 14:09 |
|
Hi Peter,
You're right. I have problem in displaying the image. The text and bullets with colours
work fine.
As you suggested, the image gets displayed when I specify a hard path but does not
work when relative path is given. However, when I use relative path in other places in
the windows form application, the image gets loaded. I face the problem only when
using it in the CDML table.
The code I currently use:
folderTable.setText(0, i, "<*block,valign=absmiddle*><*img=" +
"c:\\\\folder_15x13.png" + "*> <*/*> " + "<*block,valign=absmiddle,width=" +
getRelativeWidth(140) + ",truncate=1*><*font,color=" +
Chart.CColor(Color.Blue).ToString("X8") +"*>"+
folderDataObj.FOLDERINFO_FOLDERNAMES[i - 1] + "<*/font*><*/*>");
folderTable.setText(1, i, " <*font,color=" + (Chart.DataColor + i - 1).ToString("X8") +
"*>\\x25A0<*/font*><*block,valign=absmiddle,width=" + getRelativeWidth(60) +
",truncate=1*>" + folderSizesList[i - 1] + " " + FolderBytes[i - 1] + "<*/*>");
I have attached a screenshot of my expected output.
Kindly help me out on achieving the output with relative path. I have all images in
Resources.resx and there is no way of specifying a hard path for the images in my
project.
Meanwhile I would try a workaround by getting the location of each row and adding the
image directly to the WinChartViewer outside the table. Expecting an easier solution
ASAP.
Thanks & Regards,
Revathi
|
Re: Image in CDML table |
Posted by Revathi on Feb-27-2015 15:47 |
|
Hi Peter,
Also I would like to know how I can merge the columns in a cdml table for the first row
alone.
I have 3 columns but want only 1 column in the first row since I would be setting a
heading which should be center aligned respective to all 3 columns.
Thanks. |
Re: Image in CDML table |
Posted by Peter Kwan on Feb-27-2015 23:54 |
|
Hi Revathi,
For CDML images, ChartDirector only supports file system path. You can use any path
you like (including absolute or relative paths), but they must be file system path that
your operating system can understand. Other paths, such as URL paths, resource path to
address resources embedded in EXE or DLLs, etc., cannot be used.
Since you mentioned about "Resources.resx" (which I assume will be compiled into your
EXE or DLL as embedded resources of your application), are you using "resource path" as
opposed to file system path?
If you are referring to resource compiled into your application, I can only think two
methods:
(a) When your application is run, load the resource and save it to a file on the hard disk.
Then use that path in the CDML.
or
(b) Load the resource into a System.Drawing.Bitmap object. Then create a ChartDirector
DrawArea object, and use DrawArea.load to load the Bitmap into the DrawArea object.
After that, create an empty scatter layer (a layer with no data), and use the DrawArea
as the scatter symbol. Finally, use layer.getLegendIcon to obtain the scatter symbol in a
format that can be used in CDML. It should like:
Bitmap obj = .... your code to load the resource as a Bitmap object ....
DrawArea d = new DrawArea();
d.load(obj);
ScatterLayer layer = c.addScatterLayer(null, null);
layer.getDataSet(0).setDataSymbol3(d);
string CDML = "<*block,valign=absmiddle*>" + layer.getLegendIcon(0) + "<*/*> ......";
To merge the columns in a CDML table, simply add a cell that spans 3 columns with
CDMLTable.setCell. For example;
//A cell at (0, 0) spanning 3 columns and 1 row
myTable.setCell(0, 0, 3, 1, "My Title");
Hope this can help.
Regards
Peter Kwan |
|