amCharts: Always show 0 on value axis and enable negative velues to be displayed

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

I have got this silly problem.

I am creating a simple serial chart, displaying columns for two simple data series. The values are quite clse to eachother so amCharts decides to hide the 0 value axis and dislay only the relevant data. This is all good, but the thing is that I need to be able compare my columns visually. I also want to hide the labels on the value axis at some point.

Generally what I get now is this:

As you can see, value axis starts counting from 22.5. I need it to always start counting from 0, so I can compare the columns relatively to each other in a visual way. I know I can set the minimum propert of the value axis to 0 to achieve my desired result. But when I set any of the values to be negative, it does not display on the chart.

This is what I get with the minimum property set to 0 and one of the data points set o a negative value:

Here is a demo of my problem: http://jsfiddle.net/gregzx/scyhwws4/1/ minimum set to 0 and one of the values set to a negative value.

Summing up: I need to always display the 0 value on the value axis AND be able to display negative values. Any hints will be much appreciated!

回答1:

You could use a negative value for the minimum setting as well. As an example, you could set your minimum value to -30 and the maximum setting to 30.

This also makes sure that the 0-line is in the vertical middle.

var chart = AmCharts.makeChart("chartdiv", {   "type": "serial",   // ...   "valueAxes": [{     "minimum": -30,     "maximum": 30   }],   // ... }); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!