有人问到如何自定义AnyChart 图表的轴标签属性,实际上,我们是无法自定义其属性的。但我们可以通过将轴标签换为其他标签的方式来改变其属性。
以 label_settings节点为例,用数据标签替换轴标签:
<label_settings enabled="true">
<position anchor="XAxis" />
<background enabled="false"/>
<format>{%Name}({%phone})</format>
</label_settings>
要禁用原来的轴标签,将 enabled 设置为"false":
<x_axis enabled="true"> <labels enabled="false"/> </x_axis>
你也可以用extra 标签替换数据标签:
<extra_labels>
<label enabled="true">
<position anchor="Center" />
<font color="White"/>
<format>{%Value}</format>
</label>
</extra_labels>
以下是带有自定义属性"phone"的数据标签放在X轴上的代码示例:
<anychart>
<charts>
<chart plot_type="CategorizedHorizontal">
<data_plot_settings default_series_type="Bar">
<bar_series>
<label_settings enabled="true">
<position anchor="XAxis" />
<background enabled="false"/>
<format>{%Name}({%phone})</format>
</label_settings>
<extra_labels>
<label enabled="true">
<position anchor="Center" />
<font color="White"/>
<format>{%Value}</format>
</label>
</extra_labels>
</bar_series>
</data_plot_settings>
<data>
<series name="HQ">
<attributes>
<attribute name="location">LA</attribute>
</attributes>
<point name="John" y="17000">
<attributes>
<attribute name="phone">555-1267</attribute>
</attributes>
</point>
<point name="Jake" y="19000">
<attributes>
<attribute name="phone">555-6790</attribute>
</attributes>
</point>
<point name="Peter" y="18000">
<attributes>
<attribute name="phone">555-0112</attribute>
</attributes>
</point>
</series>
</data>
<chart_settings>
<title enabled="false"/>
<axes>
<y_axis enabled="true" position="Opposite">
<scale minimum="0"/>
</y_axis>
<x_axis enabled="true">
<labels enabled="false"/>
</x_axis>
</axes>
</chart_settings>
</chart>
</charts>
</anychart>

本文介绍了一种通过替换轴标签来实现自定义AnyChart图表轴标签属性的方法。具体操作包括使用数据标签或额外标签替代默认轴标签,并展示了具体的XML配置示例。
4398

被折叠的 条评论
为什么被折叠?



