### A new ternary graph implementation

Posted:

**Fri Nov 15, 2019 12:17 am**As you know, I am quite disappointed with the Ternary Series implementation in TeeChart. A ternary plot is simply an X-Y plot, as there are only 2 independent variables (Z is always equal to 100 - X% - Y% where X% = X/(X+Y+Z)*100 and Y% = Y/(X+Y+Z)*100. This means there is no need to use 3D charting code. In fact, ternary data can be plotted on a simple X-Y chart, but it doesn't look so good and is less easy to understand, so special triangular exes are employed.

I have attached a spreadsheet which shows my thinking. On the first spreadsheet, data is plotted on a simple X-Y plot. The Z-axis is in the direction of the blue arrow, at right-angles to the diagonal edge of the chart. As you can see, the Z-values are correctly located at 80, 60 and 40% respectively, as shown below. In the second sheet, I have drawn sloping "axes", and again plotted X-Y data. To do this, the X% and Y% values need to be recalculated using the following formulae:

X% Ternary = X% + Y% * cos(60°)

Y% Ternary = Y% * sin(60°)

Examining the chart, it is clear that the X%, Y% and Z% values are plotted correctly. Finally, XValues (in Delphi) data should always correspond to the value at the right vertex of the graph, and YValues data to the top vertex of the graph. In the current formulation, XValues corresponds to the top vertex and YValues to the right vertex, apparently following the clockwise rotation of the axes in one configuration. however, the order or rotation of the axes is arbitrary, and the true axis direction for each vertex is a line from the mid-point of the side opposite the vertex to the corresponding vertex. It is just convention to draw the axis on one adjacent side of the triangle or the other. In the third spreadsheet, I have shown three axis configurations commonly in use, an apparent clockwise rotation, and anti-clockwise rotation and where just the x-axis and the y-axis are shown. The data is plotted in exactly the same place for all three configurations. The important aspect is the location of the vertex, so whatever is at the right vertex uses XValues and whatever is at the top axis uses YValues.

The advantage of an implementation like this is that Line Series, Point Series and FastLine Series should be able to be used, just as for a regular XY plot. The implementation should offer the choice of the three axis configurations, and hopefully the chart will be able to be zoomed just like a regular X-Y plot.

Best regards

Errol

I have attached a spreadsheet which shows my thinking. On the first spreadsheet, data is plotted on a simple X-Y plot. The Z-axis is in the direction of the blue arrow, at right-angles to the diagonal edge of the chart. As you can see, the Z-values are correctly located at 80, 60 and 40% respectively, as shown below. In the second sheet, I have drawn sloping "axes", and again plotted X-Y data. To do this, the X% and Y% values need to be recalculated using the following formulae:

X% Ternary = X% + Y% * cos(60°)

Y% Ternary = Y% * sin(60°)

Examining the chart, it is clear that the X%, Y% and Z% values are plotted correctly. Finally, XValues (in Delphi) data should always correspond to the value at the right vertex of the graph, and YValues data to the top vertex of the graph. In the current formulation, XValues corresponds to the top vertex and YValues to the right vertex, apparently following the clockwise rotation of the axes in one configuration. however, the order or rotation of the axes is arbitrary, and the true axis direction for each vertex is a line from the mid-point of the side opposite the vertex to the corresponding vertex. It is just convention to draw the axis on one adjacent side of the triangle or the other. In the third spreadsheet, I have shown three axis configurations commonly in use, an apparent clockwise rotation, and anti-clockwise rotation and where just the x-axis and the y-axis are shown. The data is plotted in exactly the same place for all three configurations. The important aspect is the location of the vertex, so whatever is at the right vertex uses XValues and whatever is at the top axis uses YValues.

The advantage of an implementation like this is that Line Series, Point Series and FastLine Series should be able to be used, just as for a regular XY plot. The implementation should offer the choice of the three axis configurations, and hopefully the chart will be able to be zoomed just like a regular X-Y plot.

Best regards

Errol