Gradient on Chart3D surface plot not working

A discussion forum for Orson Charts (a 3D chart library for the Java platform).
Locked
JohnGarnham
Posts: 3
Joined: Mon Nov 14, 2016 5:47 pm
antibot: No, of course not.

Gradient on Chart3D surface plot not working

Post by JohnGarnham » Mon Nov 14, 2016 6:28 pm

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:

Code: Select all

@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:

Code: Select all

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: http://i.imgur.com/F2iYFh1.png

JohnGarnham
Posts: 3
Joined: Mon Nov 14, 2016 5:47 pm
antibot: No, of course not.

Re: Gradient on Chart3D surface plot not working

Post by JohnGarnham » Wed Nov 16, 2016 7:43 pm

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.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Gradient on Chart3D surface plot not working

Post by david.gilbert » Thu Nov 17, 2016 9:52 am

Ah yes, that's it. Glad you figured it out...I sent you an email earlier today, you can disregard it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked