Roland Kofler
Roland Kofler

Reputation: 1342

In google chart API, how to change the position of axes?

When making a chart is it possible to center the origin of the axes into the middle so that a cross of axes shows up? We use a workaround, by setting the grid so that the grid line falls to the (0,0) point But then you can not use a finer lined grid layer for better visual guidance. Is it possible without workaround? For example with the following chart?

http://chart.apis.google.com/chart?chxt=x,y&chs=300x150&cht=s&chd=t:12,87,-75,41,23,96,68,71,34,9|98,60,27,34,56,-79,58,74,18,76|84,23,69,-81,47,94,60,93,64,-54

A accurate research in the chart api forum and the documentation showed only workarounds. If no standard solution is available, can you think about a reason why google did not implement the positioning of axes?

Upvotes: 2

Views: 1399

Answers (1)

Miguel Silva
Miguel Silva

Reputation: 633

Seems to me that every google chart is on a [0% to 100%] range. Só if you want different values (like negative ones) you are going to need some arithmetics to accomplish it.

I've also made a workaround to this problem. Using the grid with 50% step strategy. In my case, due to my X and Y axes ranging from -100 to 100 the function i'd have to apply to any values would be: f(v) = (v - 100) / 2.

There's one element that could be added to make this solution complete. If only the API provided multiple grids with different resolution (different step sizes) another finer lined grid layer could be added.

IMHO google charts API provides lower level calls to control visual elements on charts. I'd say that the missing element here is the multiple grids to allow the finer lined layer. With those elements a upper level API could be built either by google or encapsulated on a wrapper lib like charts4j. This upper level API should handle arithmetics and issues like this two grids.

Upvotes: 2

Related Questions