[英]How to set the initialValue of the trendLine as the max value of Value Axis in AmCharts?
I'm using AmCharts to populate my data. 我正在使用AmCharts填充数据。 I'm displaying trend lines in my chart.
我在图表中显示趋势线。 Is there any way to set the max value of the Value Axis as the
initialValue
of the trendiine ? 有什么方法可以将“值轴”的最大值设置为趋势的
initialValue
吗?
var trendLines = [{
"initialValue": 1800,
"initialCategory": 1997,
"lineColor": "#050",
"lineThickness": 1,
"dashLength": 5
"finalValue": 0,
"finalCategory": 1997
}
Here is a code pen demo with static values in initialValue
这是在
initialValue
具有静态值的代码笔演示
If you have a static/hard-coded minimum
and maximum
in your value axis, you could do what Robbert mentioned in the comments. 如果您在值轴上具有静态/硬编码的
minimum
和maximum
,则可以执行Robbert在注释中提到的操作。 If you want to dynamically set it, you can use the init
event to access the valueAxis' read-only min
and max
properties, which correspond to the calculated minimums and maximums of the valueAxis and add/set the trendline(s) there. 如果要动态设置它,则可以使用
init
事件访问valueAxis的只读min
和max
属性,这些属性与计算出的valueAxis的最小值和最大值相对应,并在那里添加/设置趋势线。 Here's an example of creating a new trendline that goes from the first category and maximum value, to the last category and minimum value: 这是创建一个新趋势线的示例,该趋势线从第一个类别和最大值到最后一个类别和最小值:
var chart = AmCharts.makeChart("chartdiv", {
//other settings omitted
"listeners": [{
"event": "init",
"method": function(e) {
var trendline = {
"initialValue": e.chart.valueAxes[0].max, //max axis value
"finalValue": e.chart.valueAxes[0].min, //min axis value
"initialCategory": e.chart.dataProvider[0][e.chart.categoryField],
"finalCategory":e.chart.dataProvider[e.chart.dataProvider.length - 1][e.chart.categoryField]
};
e.chart.trendLines.push(trendline);
e.chart.validateNow();
}
}]
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.