|
Rose label to graph distance |
Posted by JP on May-09-2012 08:28 |
|
Hi Peter -- I've got another graph going. This time I am using the rose as a wind direction and windspeed gauge. Is there a way to reduce the distance between the label and the graph?
Also, i had to do some weird stuff to get it working. Mainly with the wind (wind speed) and winddir (wind direction in degrees) as (-1) doubles and the array. I really just want the wind speed to show up and the direction. I have no interest in keeping a history. Maybe a pointer to clean it up?
Thanks for looking ... code and screenshot below. I left some of the sample code in this so you can see where I started (i.e. data, angles, etc.)
JP
>>>>
// Data for the chart
'dim data(-1) as double = array(9.4, 1.8, 2.1, 2.3, 3.5, 7.7, 8.8, 6.1, 5.0, 3.1, 6.0, 4.3, 5.1, 2.6, 1.5, 2.2, 5.1, 4.3, 4.0, 9.0, 1.7, 8.8, 9.9, 9.5)
dim wind(-1) as double
'dim angles(-1) as double = array(0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345.0)
dim winddir(-1) as double
wind = array(val(dataArray(10)))
winddir = array(val(NthField(TextFieldWindDir.Text, " ", 1)))
// Create a PolarChart object of size 460 x 460 pixels, with a silver background
// and a 1 pixel 3D border
'dim c as new CDPolarChartMBS(460, 460, CDPolarChartMBS.silverColor, &h000000, 1)
dim c as new CDPolarChartMBS(CanvasWind.Width, CanvasWind.height, CDPolarChartMBS.silverColor)', &h000000, 1)
// Add a title to the chart at the top left corner using 15pts Arial Bold Italic
// font. Use white text on deep blue background.
'c.addTitle("Wind Direction", "arialbi.ttf", 15, &hffffff).setBackground(&h000080)
// Set plot area center at (230, 240) with radius 180 pixels and white background
c.setPlotArea(92, 90, 65, &hffffff)
// Set the grid style to circular grid
c.setGridStyle(false)
// Set angular axis as 0 - 360, with a spoke every 30 units
c.angularAxis.setLinearScale(0, 360, 30)
c.angularAxis.setLabelStyle.setFontSize(7)
// Add sectors to the chart as sector zones
dim i,count as integer
'count=UBound(data)
'for i=0 to data
'c.angularAxis.addZone(angles(i), angles(i) + 15, 0, data(i), &h33ff33, &h008000)
c.angularAxis.addZone(winddir(i), winddir(i) + 10, 0, wind(i), &h33ff33, &h008000)
'next
// Add an Transparent invisible layer to ensure the axis is auto-scaled using the
// data
call c.addLineLayer(wind, CDPolarChartMBS.kTransparent)
// Output the chart
CanvasWind.Backdrop=c.makeChartPicture
|
Re: Rose label to graph distance |
Posted by JP on May-10-2012 00:10 |
|
Peter -- one other question. I am trying to set the background of the polar chart to a png image. I can't figure out a way to do that. I am after the portion that is silver, not the white area in the center. I've tried transparent, but all I get is black around the outer portion of the circle (the silver portion).
I've tried:
dim c as new CDPolarChartMBS(CanvasWind.Width, CanvasWind.height, CDPolarChartMBS.kTransparent)
c.setBgImage("canvas_wind.png", 5)
I've also tried:
dim c as new CDPolarChartMBS(CanvasWind.Width, CanvasWind.height)
c.setBgImage("canvas_wind.png", 5)
for the background image, but it does not show in either case. Transparent shows black, and the second option shows white.
Thanks
JP |
Re: Rose label to graph distance |
Posted by Peter Kwan on May-10-2012 00:17 |
|
Hi JP,
For the distance between the label and the graph, you may configure it using AngularAxis.setLabelGap. For example:
c.angularAxis().setLabelGap(1)
(*** Note: The above is only an example. The gap is probably too small if set to 1. ***)
If you only have one value to plot, you can just plot the value. There is no need to store it an array:
dim wind as double = val(dataArray(10))
dim winddir as double = val(NthField(TextFieldWindDir.Text, " ", 1))
c.angularAxis.addZone(winddir, winddir + 10, 0, wind, &h33ff33, &h008000)
*** Note: I am not familiar with RealBasic and am not sure if the above code is correct. You may need to debug it. ***
Hope this can help.
Regards
Peter Kwan |
Re: Rose label to graph distance |
Posted by JP on May-10-2012 00:34 |
|
Thanks Peter --
I switched over to not using the array. I do get an error with:
call c.addLineLayer(wind, CDPolarChartMBS.kTransparent)
The error is: "Parameters are not compatible with this function"
Also, any thoughts on the background image?
JP |
Re: Rose label to graph distance |
Posted by Peter Kwan on May-10-2012 00:51 |
|
Hi JP,
I am not familiar with RealBasic, but in Visual Basic, this can be solved with:
call c.addLineLayer(array(wind), CDPolarChartMBS.kTransparent)
Hope this can help.
Regards
Peter Kwan |
Re: Rose label to graph distance |
Posted by JP on May-10-2012 01:10 |
|
Peter -- that took care of it. Thanks.
Have you had a chance to ponder my second note in this thread? I am trying to add a background image for the graph. I can't figure out a way to do that. I am after the portion that is silver, not the white area in the center. I've tried transparent, but all I get is black around the outer portion of the circle (the silver portion).
I've tried:
dim c as new CDPolarChartMBS(CanvasWind.Width, CanvasWind.height, CDPolarChartMBS.kTransparent)
c.setBgImage("canvas_wind.png", 5)
I've also tried:
dim c as new CDPolarChartMBS(CanvasWind.Width, CanvasWind.height)
c.setBgImage("canvas_wind.png", 5)
for the background image, but it does not show in either case. Transparent shows black, and the second option shows white.
Sorry for the re-post, but thought it would be easier to find.
Thanks
JP |
Re: Rose label to graph distance |
Posted by JP on May-10-2012 02:21 |
|
Peter -- I finally figured out the background image. One problem, I would like the image to blend in better with the overall background of the app. The image is an exact x y location of the background image. So I am hoping to blend in better with the app background.
I'm posting the code below as well as a screen shot.
JP
>>>
Dim f as FolderItem
f =SpecialFolder.Documents.Child("Images").Child("sky_canvas_wind.jpg")
// Data for the chart
dim wind as double = val(dataArray(10))
dim winddir as double = val(NthField(data, ",", 5))
// Create a PolarChart object of size of canvas
dim c as new CDPolarChartMBS(CanvasWind.Width, CanvasWind.height, CDPolarChartMBS.kTransparent)
c.setWallpaper(f)
// Set plot area center at (92, 90) with radius 72 pixels and silver background
c.setPlotArea(92, 90, 72, &hF2F2F2)
// Set the grid style to circular grid
c.setGridStyle(false)
// Set angular axis as 0 - 360, with a spoke every 30 units
c.angularAxis.setLinearScale(0, 360, 30)
c.angularAxis.setLabelStyle.setFontSize(7)
call c.radialAxis.setLabelStyle "",7
c.angularAxis.setLabelGap 2
// Add sectors to the chart as sector zones
c.angularAxis.addZone(winddir, winddir + 10, 0, wind, &h33ff33, &h008000)
// Add an Transparent invisible layer to ensure the axis is auto-scaled using the
// data
call c.addLineLayer(array(wind), CDPolarChartMBS.kTransparent)
// Output the chart
CanvasWind.Backdrop=c.makeChartPicture
>>>
|
Re: Rose label to graph distance |
Posted by JP on May-10-2012 06:15 |
|
Peter -- I solved the problem by adjusting the brightness in Photoshop. Now the graph looks like it is floating on top on the app window. See attached screenshot.
JP
|
|