阈值主要根据一些预先定义的条件,用于颜×××表元素,让你的数据输出可视化。
创建阈:
若要创建阈需要在 <chart>节点里创建 <thresholds>节点,并在地方一个或几个条件命名阈值:
<chart>
<thresholds>
<threshold name="SampleThreshold">
<condition name="Excellent Rating" type="greaterThanOrEqualTo" value_1="{%YValue}" value_2="10000" color="Red" />
</threshold>
</thresholds>
</chart>
简单的定义语法如下:定义条件
<threshold name="SampleThreshold">
<condition name="From 100 to 200" type="between" value_1="{%YValue}" value_2="100" value_3="200" color="Red" />
<condition name="Negative" type="lessThen" value_1="{%YValue}" value_2="0" color="Blue" />
</threshold>
还可以使用{%customattributename}自定义属性值。在上面的例子中,所有的从100到200的值将会被显示为红色,所有的负值,将会被显示为蓝色。就如你所看见的,你可以在value_1、value_2 、value_3中使用关键字,你可以使用在本文的末尾找到的关键字属性完整列表。
在下面的示例中,我们将创建柱形图来显示当月不同经理的销售额,小于10.000的将会用暗红色表示,从10.000到20.000的将会又能够金色表示,大于20.000的将会用绿色表示,tooltip将会显示销售数据和评估。
条件类型:
这里有8种条件类型,下面的表格中就是浙西条件类型和相关的描述:
一旦定义了阈值,你就可以将它们应用到图表上所有的数据上或数据列,想要实现这一点,是需要设置一下阈值属性的<data>或<series>节点,现在就来看看AnyChart阈值应用。
<data threshold="Threshold1">
<series name="Series1" threshold="Threshold2">
</series>
<series name="Series2">
</series>
</data>
阈值自定义属性
你可以将任何的数据添加到条件上边来使用这些在标签上或tooltip上的数据,比如说,你可以描述一个条件,然后将这个条件放在标签里面。
为了添加自定义属性到条件,需要在<condition>中创建<attribute>节点,并将一些<attribute>节点放在你需要的地方。
<thresholds>
<threshold name="TempreatureTreshold">
<condition name="c1" type="lessThanOrEqualTo" value_1="{%YValue]" value_2="127" color="Red">
<attributes>
<attribute name="Description">The price is less or equal than 127 - and that is a very dangerous situation!</attribute>
</attributes>
</condition>
<condition name="c2" type="greaterThan" value_1="{%YValue}" value_2="127" color="Yellow">
<attributes>
<attribute name="Description">The price is greater than 127 - and that is fine.</attribute>
</attributes>
</condition>
</threshold>
</thresholds>
在标签和Tooltips中使用阈值
在下面的示例中,将会看见显示发动机温度的区域图,使用阈值,标签和tooltip来定义阈值的颜色,阈值使用描述和细节阈值条件的自定义属性。
可以按照下面的代码自定义条件属性:
<thresholds>
<threshold name="TempreatureTreshold">
<condition name="c1" type="lessThanOrEqualTo" value_1="{%YValue}" value_2="153" color="Black">
<attributes>
<attribute name="Description">DANGER!</attribute>
<attribute name="Details">The Temprature is less than or equal to 154.</attribute>
</attributes>
</condition>
</threshold>
</thresholds>
在标签中设置使用的条件数据:
label_settings enabled="true" rotation="90">
<format>{%ConditionDescription}</format>
</label_settings>
在tootip中显示脚本
<tooltip_settings enabled="true">
<format>Temp: {%YValue}
{%ConditionDescription} {%ConditionDetails}</format>
</tooltip_settings>
参考资料:Flash图表AnyChart应用教程
转载于:https://blog.51cto.com/datavisual/1297692