1

I am trying to code a class named MultipleAxisLineChart. As its name says - it will be a LineChart which will have multiple axis (I assume that all additional axes will be placed either on Side.LEFT or Side.RIGHT).

All axes on given side will be positioned by tickLabelGapProperty. Right axes should be additionaly x-translated by the sum of left side axes' width.

The problem arised when I came to the moment of computing the preferred chart width (given my previous assumptions the charts plot areas would be of the same size, so they could be placed on the top of each other). Property LineChart#widthProperty returns the width of whole LineChart object (including y-axis and gap property) - so this one will certainly not be the best candidate for setting the same width for all LineCharts plot areas (as I would have to compute different width for each chart - remember that tickLabelGap is different for each one).

I am able to get (and even set) axis width (just Axis#widthProperty), but not LineChart plot area width. So, my question is - is there a way to arbitrary set the width of LineChart plot area so that all areas in different charts would have the same width?

update

I am trying to achieve effect similar to HighCharts multiple axes: (C) Screen from HighCharts Demo website My attempt is to use StackPane and add all charts as children. I would be able to control the size of Chart by setting StackPane width.

Maciej Dobrowolski
  • 11,561
  • 5
  • 45
  • 67
  • What are you doing? Are you subclassing LineChart and creating a custom chart with multiple axes or are you [using a StackPane to overlay multiple charts on top of each other](http://stackoverflow.com/questions/9667405/how-to-draw-multiple-axis-on-a-chart-using-javafx-charts)? Is this [solution for multiple axes on a chart](http://stackoverflow.com/questions/26303111/move-tick-label-javafx-2) useful (it is a bit of a hack)? I advise to tighten the question up and make it easier for somebody to answer ([mcve](http://stackoverflow.com/help/mcve) or image). – jewelsea Oct 23 '14 at 22:40
  • @jewelsea Thanks for reply. I have updated my question. I am subclassing StackPane. "Solution with multiple axes on a chart" is not exactly of what I am looking for. I think the attached picture would speak for itself :) – Maciej Dobrowolski Oct 23 '14 at 22:50
  • A picture tells a thousand words, beautiful chart.. try starting your work from [this sample](https://gist.github.com/jewelsea/3668862) in combination with the answer to the multiple axes question and see if you can replicate the chart in your question. Bonus points if you can [make it dynamic](https://gist.github.com/jewelsea/2129306). Subclassing rather than stacking is probably the "right" way to do this, but would be more complex to achieve. – jewelsea Oct 23 '14 at 22:54

1 Answers1

1

The problem has been solved. There was no need to use tickLabelGapProperty to position LineChart. It can only spoil all idea, because it's transition is counted to component width.

Moving axis can be simply done by Axis#setTranslateX(double).

Coming back to MultipleAxisLineChart - I have created something similar to the one I have presented. Here you can find out more.

Maciej Dobrowolski
  • 11,561
  • 5
  • 45
  • 67