有人問到如何自定義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>