FoxCharts/GDIPlusX

Topics: Bug Information, Enhancement Request
Dec 9, 2008 at 12:22 AM
I've just begun to use GDIPlusX and FoxCharts and could use a bit of help, please.

The code is evaluating DNA data -- generating statistics and looking at distribution of repeat values (alleles) at various Y-DNS marker locations:
-- please see http://mykindred.com/ck/  (temporary pages)

One problem I'm having -- I get the error below and the data looks good to me (i.e. not missing and it is numeric and similar to all the other data sets), so I can't figure out what is causing it:
Unhandled Structured Exception
error no. 2071
Message: User Thrown Error
UserValue: (Object)
Details:
Procedure: _beforedraw
LineNo: 94
Line of Code: ENDTRY
Line number: 96
Program with error: FOXCHARTS._BEFOREDRAW

Two other problems:
 - charts with only one set of data don't generate the correct graph:
-- e.g.: http://mykindred.com/ck/y-images/003D406S1.png

Suggestions:
 - Many of the data sets have values like 1500 next to 1 or 2.  The legend for the small values print on or below the bottom graph boundary.
 ** it would be nice to have the option to place a limit on how low the legend can be placed -- e.g. not allow it to drop below the bottom boundary.

 - allow setting the maximum size of the bars -- so charts with 5 or 6 bars will look similar to ones with only 1 or 2

 - add a Margin setting for the axis legends so they can be positioned further apart.

Question:
 - Is there a way to include IPTC Photo Metadata in the jpeg files? (e.g. copyright, date, subject, etc.)

Thanks to everyone who has worked on this -- it's really very nice.
Tom





Developer
Dec 15, 2008 at 9:03 AM
Hi Tom,

I'm just copying the answers that I provided in the Foxite forums.
If someone is interested in the questions posted here, please follow the Foxite link, where you'll find more detailes info and pictures.

http://www.foxite.com/archives/0000207523.htm

Hi Tom,

> First -- kudos to all who have worked on this. It is very useful.

Thanks !
Hope you enjoy.
Your feedback and suggestions are very valuable for the improvement of the class.


> Please see the image at
> - http://mykindred.com/ck/y-images/000D390.png

Oops... There's no image there !


> - http://mykindred.com/ck/

> Here are my questions:

> 1 - is there a way to keep the shape legend above the X-axis ?

What exactly you want here ?
Can you produce a picture showing what you'd like to obtain ?
I presume you want to draw the shape legends in the lower part of the bars ?


> 2 - is there a way to specify a margin around the X-axis legend
Sure !
Please set the properties MarginTop, MarginLeft, MarginRight and MarginBottom.
For global margin setting, you can use the Margin property as well. The values passed are the quantity of pixels.


> 3 - for some reason the X-axis legend is not centered ??

That's true.
Recently I fixed this, Please download the most recent version, 1.00.26 from here.
At the link below you'll find the latest version I have. These versions contain the fixes for the most recent bugs since version 1.00 RC, and some few enhancements.
Version 1.00.27 is stable, and you can try it:
http://www.codeplex.com/VFPX/Release/ProjectReleases.aspx?ReleaseId=19009


> 4 - can I have a second shape legend -- I need to show percentage against the largest value.

Not yet.
I plan to allow the full manipulation of the shape legends.
You'll be able to put any value or text on any shape you desire... But right now all you can do is to change the formatting of the values.

For Pies or Doughnut charts, there's the possibility to draw the percentages, setting the properties

.PieShowPercent = .T.
.ShowValuesOnShapes = .T.

In fact it would be easy to expand it to be used in the bar charts.
I hope to do so soon.


> ** and this one is, I believe, a GDIPlusX question
>
> 5 - how do I place the logo on the graph at the time the chart is created?

Yes !
That's the GdiPlusX part, but it is really very simple, and you already have a working sample for this:

In the samples folder of FoxCharts, please open the sample "ChartsSample_old.scx"
Open the method "AfterChart" in the FoxCharts object.

Here's the code you'll find there, with some additional comments:

* The loGfx object is the GdiPlusX Graphics object, that allows you to
* draw anything in the canvas of your chart

LOCAL loGfx as xfcGraphics
* Always declare your Gdi+X objects correctly in order to obtain Intellisense support

loGfx = This.oGfx 

WITH _Screen.System.Drawing
   loGfx.DrawImage(.Bitmap.FromFile("\Images\vfpxpoweredby_alternative.Gif"),0,0)
 * Make sure to put there the full path of your image
ENDWITH 


That's all the basic stuff you need.
In the sample above The logo of VFPX was drawn in the coordinate (0,0). Change it as you desire. You'll probably want to leave an additional margin in order to make space to draw you logo outside the chart. So you may set the property MarginTop, leaving some pixels needed to draw the logo.

Note that this way , your logo will be a part of the whole chart, so when you save it it will be permanentky there !



More details you can find at the HELP file of FoxCharts, at the method "AfterChart"


> 6 - I'd also like to write the text above the logo programmatically so the date can be included and the text changed.

Sure !
That's a GdiPlusX task too:

Here's a new improved sample code for your AfterChart method:

LOCAL loGfx as xfcGraphics
loGfx = This.oGfx 

WITH _Screen.System.Drawing
	loGfx.DrawImage(.Bitmap.FromFile("\Images\vfpxpoweredby_alternative.Gif"),0,0)

LOCAL loFont as xfcFont
loFont = .Font.New("Tahoma", 14)

loGfx.DrawString("My Custom Text", loFont, .Brushes.DarkGreen, 0, 14)

ENDWITH 





For more advanced usages of GdiPlusX, please ask again, or search directly in my blog, or at the references pages of GdiPlusX, whwre you'll find many links with GdiPlusX samples for drawings.


> Right now, I create the chart and then, in a separate step, I add the legend. I also notice that I cannot add the legend to the chart and then save it back on the same file, so I have to save to a separate directory and then copy over the original files.

In the most recent versions of FoxCharts you have some new legends possibilities, putting your legends in 10 predefined positions. Maybe you can find it useful to avoid having to create your legends in a separate step, and let FoxCharts do it all for you.



The property is:

LegendPosition Numeric, (0-9)

0 - Vertical Top Left
1 - Vertical Bottom Left
2 - Vertical Top Right
3 - Vertical Bottom Right
4 - Horiz Top Left
5 - Horiz Top Center
6 - Horiz Top Right
7 - Horiz Bottom Left
8 - Horiz Bottom Center
9 - Horiz Bottom Right


Well, if you still insist on creating your own legends, you can do the following:

1 - Create your legend before drawing your chart, putting all the legends inside a Container
2 - Use GdiPlusX to capture the image of your legend:

Local loBmp as xfcBitmap
With _Screen.System.Drawing
   loBmp = .Bitmap.FromScreen(Thisform.Container1)
   loBmp.Save("c:\Test.png", .Imaging.ImageFormat.Png")
EndWith


3 - Use the techniques shown above to draw the legends in your chart canvas


Hope this helps !

Regards,

Cesar
Developer
Dec 15, 2008 at 9:04 AM
And here's the 2nd answer:



Hi Tom,

> both the links above work for me ??

Ok, I got it. Now I downloaded it directly from the link instead of opening a web page.


> I downloaded your new version -- and think you've introduced another problem ... or else I'm doing something wrong.
> Please see this page -- I made a little html index page to make it easier:
> http://mykindred.com/xfc/

Thanks for the images.
Yes, I saw the problem, but really could not reproduce it.
Can you please send me the initialization information ?
That's very easy to do:

Immediately after you call "DrawChart()", add the following line:

STRTOFILE(Thisform.FoxCharts1.GetChartProperties(), "c:\FoxChartsScript.txt")


This will generate a script containing all the properties used to generate the current chart. Please send it to me directly to vfpimaging at hotmail dot com or post it here. Having this, I'll be able to reproduce your chart, and your issues, I hope normal smile


> The logo on it was created in a separate step. I haven't had a chance yet to try your suggestion on doing it during the chart creation process -- believe my problem was the code

Yes, please reproduce the steps from the previous message, they should do the job !


> This "old" image is the one where the X-axis legend is not centered.

Thanks for the pic, and for confirming that the alignment of the X Axis is correct now


> The second image link "new xfc source" -- the problem here is that now the Y-axis legend is scrunched up into the Y-scale legend.

Yeah, I'll be waiting for your script in order to fix it normal smile

> The chart has Y-axis values to 1600, but many of the bars represent Y-values less than 10. The shape legends for these fall on or below the X-axis. It would be nice to force these low-value legends to never drop ON or BELOW the X-axis.

Ok, I got it.
I have some suggestions so far:

Rotate the legend shapes, and show it in an angle of 315 or 270 degrees:
See the pics below, where I tried to reproduce your chart.

Pls note that it is important to set the "Alignment" property to "0 - Left" to obtain better results:



With .ShapeLegend
    .Alignment = 0 && Left
    .FontSize = 8
    .Format = '9,999'
    .Rotation = 315 && please try using 270 as well !
EndWith
.ShowSideLegend = .F.
.ShowValuesOnShapes = .T.



ANGLE = 315






ANGLE = 270





> You can see what I've given him so far at:
> http://www.kerchner.com/r1bproject/cssmarkerstats/charts.htm

VERY NICE !
Thanks for showing to me !


Regards,

Cesar