ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Vertical Linear Meter as fill tank auto scale
Posted by JP on Apr-30-2012 00:28
Attachments:
Hi Peter --

I am using the vertical linear meter as a fill tank for my daily rain and solar readings from my weather station.  I am using the code pretty much from the examples.  I am painting the meter in a canvas.  I have the scale set at 0,0 so I do not see it -- allowing me to use the entire canvas height and width as the graph area.  Also I am not using a pointer.  I set the scale upper limit manually via a preference setting.  My question is -- is it possible to use an auto scale?

Note the two canvas' are the vertical ones above the main graph in the photo below -- one on the left (solar) and one on the right (day rain).  If there are no readings they disappear.

Below is the code for the solar meter (fill tank).

Thanks
JP

>>>


  // Create an LinearMeter object of size 60 x 265 pixels, using silver background

  dim m as new CDLinearMeterMBS(Canvas3.width, Canvas3.Height, CDBaseChartMBS.silverColor)

  // Set the scale region top-left corner at (0, 0), with size of 44 x 150
  // pixels. The scale labels are located on the left (default - implies vertical
  // meter)
  m.setMeter(0,0, 44, 150)

  // Set meter scale from 0 - to preference setting GraphSolar

  m.setScale(0, GraphSolar)

  // Set entire zone as yellow (ffff66) -- textfield8 is the solar value

  call m.addZone(0, val(TextField8.Text), &hffff66)

  // not using deep blue (000080) pointer at the specified value
  'call m.addPointer(val(TextField8.Text), &h000080)

  // Add a text box label at top-center (30, 5) using Arial Bold/8 pts/deep blue
  // (000088), with max width to force word wrap (needed on the rain fill tank)
  call m.addText(22, 5, "Solar", "arial.ttf", 8, &h000088, CDBaseChartMBS.kTopCenter).setMaxWidth(44)

  // Add a text box to show the value formatted to 0 decimal places at bottom
  // center (22, 5). Use dark blue text

  call m.addText(22, 145, m.formatValue(val(TextField8.Text), "0"), "arial.ttf", 8, &h000088, CDBaseChartMBS.kBottomCenter)

  // Output the chart

  Canvas3.Visible=True
  Canvas3.Backdrop=m.makeChartPicture
Weather_app.jpg

  Re: Vertical Linear Meter as fill tank auto scale
Posted by Peter Kwan on May-01-2012 00:39
Hi JP,

ChartDirector currently cannot auto-scale a meter scale. For your case, if you would like auto-scaling, you may consider to use a bar chart with one bar, instead of using a linear meter.

Personally, I think auto-scaling should not be useful in your case. For example, in your chart, the Solar value is 939. If you use auto-scaling, ChartDirector may choose the scale to be 0 - 2000, which means the tank is about half full. For the Day Rain, which is 0.05, if you use auto-scaling, ChartDirector may choose 0 - 0.1 as the axis scale, which means the tank is about half full too. In fact, for a chart with one data point, ChartDirector will auto-scaling the axis to try to put the data point in the middle of the chart. It means no matter what is your data value, the tank is always about half full. So the tank would not show whether a certain value is considered "high" or "low".

Regards
Peter Kwan

  Re: Vertical Linear Meter as fill tank auto scale
Posted by JP on May-01-2012 22:56
Peter -- thanks for the reply.  I kinda figured as much, and agree it does not make sense for auto scaling with vertical meter.  The soar is seasonal, so it is not as much of an issue as the rain.  Solar can be set by season. Rain -- is not predicitable.  I may figure out a scenario that once the reading is at 90% of the scale, change the scale.

One last question -- back the the XYChart you helped me with previously -- is there a way to save it as a .jpg or a .png for uploading to a web site?

Thanks
JP

  Re: Vertical Linear Meter as fill tank auto scale
Posted by Peter Kwan on May-02-2012 00:41
Hi JP,

To save the chart as an image, the API is BaseChart.makeChart. For example:

m.makeChart("/aaa.png")

Hope this can help.

Regards
Peter Kwan

  Re: Vertical Linear Meter as fill tank auto scale
Posted by JP on May-02-2012 06:18
Thanks Peter -- OK, so I am a little dense.  Below is the code and my attempt to make it work, which of course it doesn't.

It get a "You must use the value returned by this function"

JP

  Dim date As New Date

  //
  // Paint to graph area
  //

  dim label(-1) as string = array(Str(date.ShortDate), "1:00 AM", "2:00 AM", "3:00 AM", "4:00 AM", "5:00 AM", "6:00 AM", "7:00 AM", "8:00 AM", "9:00 AM", "10:00 AM", "11:00 AM", "12:00 PM", "1:00 PM", "2:00 PM", "3:00 PM", "4:00 PM", "5:00 PM", "6:00 PM", "7:00 PM", "8:00 PM", "9:00 PM", "10:00 PM", "11:00 PM", "12:00 AM")

  labels.Append val(dataArray(1))
  AmbT.Append val(dataArray(2))
  DewP.Append val(dataArray(3))
  Hum.Append val(dataArray(4))
  Baro.Append val(dataArray(5))
  'UV.Append val(dataArray(6))
  'Solar.Append val(dataArray(7))

  dim c as new CDXYChartMBS(Canvas2.width, Canvas2.Height)

  dim legendBox as CDLegendBoxMBS
  legendBox = c.addLegend(393, 20, false, "arial.ttf", 8)
  legendBox.setAlignment(CDXYChartMBS.kBottomCenter)
  legendBox.setBackground(CDXYChartMBS.kTransparent, CDXYChartMBS.kTransparent)

  call c.setPlotArea(30,20, Canvas2.width-70, Canvas2.height-50).setGridColor(&hcccccc, &hcccccc)

  dim layer As CDLayerMBS

  layer = c.addLineLayer(AmbT, &cFF000000, "Temperature")
  layer.setLineWidth(2)
  layer.setXData(labels)

  layer = c.addLineLayer(DewP, &c00FF0000, "Dew Point")
  layer.setLineWidth(2)
  layer.setXData(labels)

  layer = c.addLineLayer(Hum, &c0000FF00, "Humidity")
  layer.setLineWidth(2)
  layer.setXData(labels)

  c.yAxis2.setColors(0, &h66aaee)', &c66CCFF00, -1, -1)

  c.yAxis2.setLinearScale(29, 31)

  layer = c.addLineLayer(Baro, &c66CCFF00, "Pressure")
  layer.setLineWidth(2)
  layer.setXData(labels)
  layer.setUseYAxis2


  'c.xAxis.setLabelFormat "{value|hh:nn:ss}"
  c.xAxis.setDateScale 0, 86400, label

  c.xAxis.setLabelStep 2

  Canvas2.Backdrop = c.makeChartPicture

  c.makeChart("/Documents/tempdew.png")

  Re: Vertical Linear Meter as fill tank auto scale
Posted by Peter Kwan on May-03-2012 00:57
Hi JP,

Actually, I have never used RealBasic before. (The RealBasic edition of ChartDirector is ported by one of our partners, not directly by us.) I am just trying to guess what is the correct syntax in RealBasic. May be it should be:

Call c.makeChart("/Documents/tempdew.png")

Regards
Peter Kwan

  Re: Vertical Linear Meter as fill tank auto scale
Posted by JP on May-03-2012 04:55
OK -- thanks.  I will play around with it.

JP