In Power Chart how to bring axis label to centre?

Hi,
I don't know how to bring the axis label to the centre of the axis

Is there any property available?

@cmallonee @PGriffith

Any possibility to make label centre?

here is the solution

@victordcq

i am trying to add "text-anchor": "middle",
"translate": "0px 45%" through scripting but its not adding

my code

item_dict = self.props.axes[len(self.props.axes)-1]
if 'label' in item_dict:
    system.perspective.print('ssss..')
    # Check if 'style' is present in the 'label' dictionary
    label = item_dict['label']
    if 'style' in label:
        # If 'style' is present, update it directly
        label['style']['text-anchor'] = "middle"
        label['style']['translate'] = "0px 45%"
    else:
        # If 'style' is not present, create it and add the desired attributes
        label['style'] = {
            "text-anchor": "middle",
            "translate": "0px 45%"
        }

my axes json
<ObjectWrapper>: {u'color': u'#757A7F', u'dataFormat': u'0,0.##', u'grid': {u'visible': False, u'color': u'#757A7F', u'style': {u'classes': u''}, u'opacity': 0.9, u'dashArray': 0L}, u'name': u'Axis 6', u'width': 60L, u'range': {u'auto': True, u'min': u'', u'max': u''}, u'style': {u'classes': u''}, u'label': {u'offset': 0L, u'style': {u'classes': u''}, u'text': u'rammmm', u'font': {u'color': u'#757A7F', u'size': 10L}}, u'tick': {u'color': u'#757A7F', u'count': u'Auto', u'style': {u'classes': u''}, u'label': {u'format': u'Auto', u'style': {u'classes': u''}, u'font': {u'color': u'#757A7F', u'size': 10L}}}, u'position': u'left'}

can you please correct what i am doing wrong here please

component is XY chart- text-anchor property is not available for this component

you made the dict but did not assign it to the property
you will have to do something like this somewhere on the bottom of your if
(this not tested code)
self.props.axes[len(self.props.axes)-1]['label'] = label

not sure why you use scripting though, if you want to do this on all the axes, you should propably use the css class way, mentioned a bit lower in the post

yes they add new axis to the chart. i need this text anchor properties also to be added that why i used script.

ok i will check the post

can you guide me how to update the css class, i am new to this topic

copy this in the advanded stylesheet.css

and give your chart the yourClass style class


(feel free to rename it ofc)

1 Like

when user add axis in front end (live project) i need to pass style class to the new axis

this scripting method is not working

if 'style' in label:
        # If 'style' is present, update it directly
        label['style']['text-anchor'] = "middle"
        label['style']['translate'] = "0px 45%"

can you give me any idea

is the style not working?

and did you try this?

yes not working

item_dict = self.getSibling("PowerChart").props.axes[6]
		    
	if 'label' in item_dict:
		system.perspective.print('ssss..')
		# Check if 'style' is present in the 'label' dictionary
		label = item_dict['label']
		if 'style' in label:
		    # If 'style' is present, update it directly
		    label['style']['text-anchor'] = "middle"
		    label['style']['translate'] = "0px 45%"
		else:
		    # If 'style' is not present, create it and add the desired attributes
		    label['style'] = {
		        "text-anchor": "middle",
		        "translate": "0px 45%"
		            }
	system.perspective.print(label)
	
	self.getSibling("PowerChart").props.axes[6]['label'] = label

then you might have to asign the whole label or even all the axes

but you should rly do the css

Solution

self.getSibling("PowerChart").props.axes[len(self.props.axes)-1]['label']['style'] = {
			  "classes": "",
			  "text-anchor": "middle",
			  "translate": "0px 45%"
			}
1 Like