I’ve managed to create circular bar in paintable canvas, something like this (smaller one is mine):
[attachment=2]dashboard_cr.png[/attachment][attachment=1]quality_bar.PNG[/attachment]
But my knowledge of java (java2D) is not sufficient…
I don’t know, how to create a text (numbers, that represent percentage), that goes around the circle (and also dots under text)…
Any help would be very appreciated…
And this is my code in repaint event of canvas:
[code]from java.awt import Color
from java.awt import Graphics
from java.awt import GradientPaint
from java.awt.geom import GeneralPath
from java.awt.geom import Rectangle2D
from java.awt.geom import Ellipse2D
from java.awt import BasicStroke
from math import *
#scaling
def scaleNum(unscaledNum, minAllowed, maxAllowed, min, max):
return (maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed
g = event.graphics
value = event.source.parent.value
value = round(value*100)/100.0 #zaokroži na dve decimalke
#print "value= " + str(value)
lblvalue = value
#if value>100.00:
value = 100.00
lblvalue = “>100”
value = -value
#print "-value= " + str(value)
#scaling
value = scaleNum(value, 0, 359, 0, 100)
#print value
unit = event.source.parent.unit
label = event.source.parent.label
print label
sirina = event.width
visina = event.height
#print visina, sirina
dX = ((event.width100)/120.0)/100
dY = ((event.height100)/120.0)/100
ratio = (event.width * g.font.size) / 370
g.scale(dX,dY)
#print "dX,dY,ratio: ", dX, dY, ratio
orgfont = g.getFont()
dimensionfont = orgfont.deriveFont(orgfont.getSize()*2.5)
arcColor = Color(0,62,105)
circleColor = Color(243,246,249)
arcColor = event.source.parent.arccolor
circleColor = event.source.parent.circlecolor
Arc
arcwidth = 10
g.setStroke(BasicStroke(arcwidth))
g.setColor(circleColor)
arc = g.drawArc(10,10,100,100,270,-360)
#circle
g.setColor(arcColor)
arc = g.drawArc(10,10,100,100,270,int(value))
#label
g.setColor(Color.BLACK)
g.setFont(dimensionfont)
#g.setFont(dimensionfont)
completelabel = str(lblvalue) + unit
stringwidth = g.getFontMetrics().stringWidth(str(label))
stringheight = g.getFontMetrics().getHeight()
#print stringwidth, stringheight
#g.drawString(str(value),(sirina/2) - (stringwidth/2), (visina/2) - (stringheight/2))
completelabel = str(value) + unit
stringwidth = g.getFontMetrics().stringWidth(str(lblvalue))
g.drawString(str(lblvalue),(sirina/2)/dX - (stringwidth/2), (visina/2)/dY)
g.setFont(orgfont)
stringwidth = g.getFontMetrics().stringWidth(str(unit))
g.drawString(str(unit),(sirina/2)/dX - (stringwidth/2), (visina/2)/dY - 25)
stringwidth = g.getFontMetrics().stringWidth(str(label))
g.drawString(label,(sirina/2)/dX - (stringwidth/2), (visina/2)/dY + 35)
[/code]
And there are some custom properties:
[attachment=0]quality_bar2.PNG[/attachment]