0

I am using orson chart's Chart3D to make a surface plot, and for some reason the graph isn't properly coloring the gradient. The code is below:

@SuppressWarnings("serial")
Function3D function = new Function3D() {
    @Override
    public double getValue(double x, double z) {
        double xKey = Math.round(x * 100) / 100;
        double zKey = Math.round(z * 100) / 100;
        if(plotValues.containsKey(new Point2D(xKey,zKey))) {
            return plotValues.get(new Point2D(xKey,zKey));
        } else {
            return 0;
        }
    }
};

String xTitle = factorSweepComboBox.getSelectionModel().getSelectedItem();
String yTitle = outputComboBox.getSelectionModel().getSelectedItem();
String zTitle = factorSweep2ComboBox.getSelectionModel().getSelectedItem();

// Create surface plot
Chart3D chart = Chart3DFactory.createSurfaceChart(
        "", 
        "", 
        function, xTitle, yTitle, zTitle);

XYZPlot xyzplot = (XYZPlot) chart.getPlot();
xyzplot.setDimensions(new Dimension3D(10, 10, 10));
ValueAxis3D xAxis = xyzplot.getXAxis();
xAxis.setRange(xLow, xUp);
ValueAxis3D zAxis = xyzplot.getZAxis();
zAxis.setRange(zLow, zUp);
ValueAxis3D yAxis = xyzplot.getYAxis();
yAxis.setRange(yLow, yUp);
SurfaceRenderer renderer = (SurfaceRenderer) xyzplot.getRenderer();
renderer.setColorScale(new GradientColorScale(new Range(yLow, yUp), 
        Color.BLUE, Color.YELLOW));
Chart3DViewer chartPanel = new Chart3DViewer(chart);      
chartPane.getChildren().addAll(chartPanel);

plotValues is a hashmap mapping a (x,z) 2D point to a double y output value. xLow, xUp, etc. are range values and are all being set correctly. yLow and yUp are what I want them to be. However, when I run the code my surface is all one color, there is no gradient at all even though the key looks correct. I have also tried:

SurfaceRenderer renderer = new SurfaceRenderer(function);
renderer.setColorScale(new GradientColorScale(new Range(yLow, yUp), 
                                Color.BLUE, Color.YELLOW));
xyzplot.setRenderer(renderer);

and the result is the same. Here is a link to a screenshot: https://i.stack.imgur.com/S1e8G.png

1 Answers1

0

I found the problem. It was due to my function only return real values on discrete x and z values, which works if the set of (x,z) matches the set in my own data hash. However, the surface renderer uses the mid-point between two "x" and "z"'s in the dataset when it plots the surface to determine the color, and because the middle point isn't in the hash it returns 0, making the whole surface one color.