简体   繁体   English

如何在XY图表类型中为x和y轴设置范围值的最小值/最大值

[英]How to set range values min/max for x and y axis in XY chart type

I am using Amcharts v3, xy chart type, (This is the example I am using https://www.amcharts.com/demos-v3/scatter-chart-v3/ ) with chartScrollbar for both x and y axis. 我正在使用xy图表类型的Amcharts v3(这是我使用https://www.amcharts.com/demos-v3/scatter-chart-v3/的示例),同时具有针对x和y轴的chartScrollbar。 How do I set the values of min and max range of Scrollbar (for both x and y) so that when i load the chart, it shows at a certain zoom level by default. 如何设置滚动条的最小值和最大值范围的值(对于x和y),以便在加载图表时默认情况下以一定的缩放级别显示。

I added two text boxes in html code to input values of x axis. 我在html代码中添加了两个文本框,以输入x轴的值。 and a function in ts file to call an api function with start end end values. ts文件中的函数可调用具有起始结束值的api函数。 but it does not trigger anything on the chart. 但它不会触发图表上的任何内容。

<input type="number" [(ngModel)]="startIndexa" name="startIndexa">
<input type="number" [(ngModel)]="endIndex" name="endIndex">
<button class="btn" type="submit" (click)="zoomXYChart()">Soom</button>

and in TS file 并在TS文件中

    zoomXYChart() {       
        this.chart.zoomToIndexes(this.startIndex, this.endIndex)       
    }        

I expect the chartScrollbar to take the values from the text boxes and zoom to that level. 我希望chartScrollbar从文本框中获取值并缩放到该级别。

zoomToIndexes only works on categoryAxis objects, which a v3 XY chart does not have. zoomToIndexes仅适用于categoryAxis对象,而v3 XY图表则没有。 You need to call zoomToValues on your chart's individual value axes, eg 您需要在图表的各个值轴上调用zoomToValues ,例如

//assuming index 0 is your X axis and index 1 is your Y axis
chart.valueAxes[0].zoomToValues(xminvalue, xmaxvalue)
chart.valueAxes[1].zoomToValues(yminvalue, ymaxvalue)

Demo: 演示:

 var chart = AmCharts.makeChart("chartdiv", { "type": "xy", "theme": "none", "marginRight": 80, "marginTop": 17, "dataProvider": [{ "y": 10, "x": 14, "value": 59, "y2": -5, "x2": 0, "value2": 44 }, { "y": 5, "x": 3, "value": 50, "y2": -15, "x2": -8, "value2": 12 }, { "y": -10, "x": -3, "value": 19, "y2": -4, "x2": 6, "value2": 35 }, { "y": -6, "x": 5, "value": 65, "y2": -5, "x2": -6, "value2": 168 }, { "y": 15, "x": -4, "value": 92, "y2": -10, "x2": -8, "value2": 102 }, { "y": 13, "x": 1, "value": 8, "y2": -2, "x2": -3, "value2": 41 }, { "y": 1, "x": 6, "value": 35, "y2": 0, "x2": 1, "value2": 16 }], "valueAxes": [{ "position": "bottom", "axisAlpha": 0 }, { "minMaxMultiplier": 1.2, "position": "left" }], "startDuration": 1.5, "graphs": [{ "valueField": "value", "bullet": "round", "xField": "x", "yField": "y" }, { "valueField": "value2", "bullet": "round", "xField": "x2", "yField": "y2" }], "marginLeft": 46, "marginBottom": 35, "chartScrollbar": {}, "chartCursor": {}, "listeners": [{ "event": "init", "method": function(e) { e.chart.valueAxes[0].zoomToValues(4, 15); e.chart.valueAxes[1].zoomToValues(0, 11); } }] }); 
 #chartdiv { width: 100%; height: 500px; } 
 <script src="https://www.amcharts.com/lib/3/amcharts.js"></script> <script src="https://www.amcharts.com/lib/3/xy.js"></script> <div id="chartdiv"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM