ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  XY Scatter plot with colored dots based on z-value
Posted by Holger on May-18-2023 12:13
Hello!

I am trying to generate and XY scatter plot wiht the color of the symbol beeing the z-value. In the same plot I like to use 2 different x-axis.
I can generate the XY scatter plot with colored Z using a 3d scatter plot with rotation 0, angle 90 and prespective 0. But then I cannot add a second x-axis like in "XYchart".
Also, in the 3d scatter plot I cannot rotate the y-axis label which would be nice.

Would it be possible to update the XY scatter plot with a symbol coloring option using z-values in the next release of ChartDirector?

Thanks

  Re: XY Scatter plot with colored dots based on z-value
Posted by Peter Kwan on May-19-2023 00:02
Hi Holger,

There is an example at:

https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=addScatterLayer+std%3A%3Amap&thread=1506359387#N1506519184

Basically, the idea is that you can use a loop to add multiple scatter layers, with each layer containing just one symbol. In this way, every symbol can be set to a different color.

If you know the colors of the symbols, then you just use those colors. If you only know the z values of the symbols, and want to convert them to colors using the "color axis", you can add an empty contour layer to the chart, and configure the color axis to the color scale you want to use. You can then query the color axis to convert the z values to colors.

The above works well if there are only a few hundred data points. If there too many data points, there will be too many layers. In this case, you can group the points of the same colors together into one layer. The link above provides an example on how to do this.

Best Regards
Peter Kwan

  Re: XY Scatter plot with colored dots based on z-value
Posted by Holger on May-19-2023 07:46
Hi Peter,

Thank you for the suggestion.
I have now implemented a zValue binning and it is working ok for XY scatter plot.
Is there a way to plot a color legend for the zValue colors like for a contour plot or surface plot?

I like to change the number of "bins" at runtime so I have to calculate the color for each bin based on the number of bins.
I would also like to use a palette like "rainbow" for the coloring.
Is there a method to calculate the color values of a palette used in ChartDirector?

The colors to a scatterlayer are added by a Hex value like "&H33FF33" (RGB values I suppose) so I would need to calculate the Hex values of for example the Rainbow-Palette.
I looked at this help page but can"t quite figure out how to get a color from a palette.
https://www.advsofteng.com/doc/cdnet.htm#colorspec.htm

I basically try to create a ColorScale like this at runtime but with varying number of bins and using a rainbow palette.
Dim colorScale() As Double = {-1.0, &H1a9850, -0.75, &H66bd63, -0.5, &Ha6d96a, -0.25, &Hd9ef8b, 0, &Hfee08b, 0.25, &Hfdae61, 0.5, &Hf46d43, 0.75, &Hd73027, 1}

I am using .NET version of ChartDirector and VB.NET. Any example is welcome.
Thanks.
Holger

  Re: XY Scatter plot with colored dots based on z-value
Posted by Peter Kwan on May-19-2023 14:06
Hi Holger,

Yes, you can obtain the color from your color scale given a z value. In brief, you just need to add a color axis to your chart. In XYChart, only ContourLayer and DiscreteHeatMapLayer has a color axis, so the code is:

Dim colorScale() As Double = {-1.0, &H1a9850, -0.75, &H66bd63, -0.5, &Ha6d96a, -0.25, &Hd9ef8b, 0, &Hfee08b, 0.25, &Hfdae61, 0.5, &Hf46d43, 0.75, &Hd73027, 1}

'Add an empty contour layer (and therefore invisible) to the chart to obtain its color axis.
Dim cAxis As ColorAxis = c.addContourLayer(Nothing, Nothing, Nothing).setColorAxis(50, 50, Chart.TopLeft, 300, Chart.Left)

'Configure the color axis to use your color scale
cAxis.setColorScale(colorScale)

'Now given a value, you can obtain the color using ColorAxis.getColor
Dim myColor As Integer = cAxis.getColor(myZValue)

In the above, the color axis is visible on the chart. This is useful for debugging and may also be useful so the user can see what the color means. If you do not wan the visible color axis, you can use c.addContourLayer(Nothing, Nothing, Nothing).colorAxis() instead of setColorAxis.

Regards
Peter Kwan

  Re: XY Scatter plot with colored dots based on z-value
Posted by Holger on May-20-2023 06:07
Attachments:
Hi Peter,

Thanks for all the suggestions.
I was able to successfully make the plot with custom color gradient.

Best
Holger
Capture4.JPG