OxyPlot WPF- Find Y value from X-Axis value - wpf

I am trying to find Y-Axis value from X-Axis but so far no luck . My graph is plotted with 10-15 points with smooth curve set to true. Now what I need to locate is probable value of Y for any given x-value. Slimier to what occurs on click of graph (i think its nearest value displayed on tracker). Please note that I cant use tracker and click events. X-axis value will be provided from external input.
sample image
http://i.stack.imgur.com/jMwJo.png

Related

Recharts: how is it possible to show only the value of ONE data point inside a Tooltip?

I am trying to implement the following example inside a Recharts LineChart: the Tooltip value is relative to the blue point, because my mouse happens to be near it, and further away from the grey point with the same x-value. If I move the mouse closer to the grey point, the tooltip content changes.
However, all available examples show that a Recharts Tooltip receives data about all the data series being drawn and that it seems not possible to discriminate the point nearest to the mouse, so that the Tooltip may provide its value only.
Is there a way to specify for which dot I want to send data to the Tooltip?
At the end of a long fruitless search, I decided to solve this problem myself.
The minimal code is published in this Github gist.
The basic problem to solve is that any standard Recharts tooltip receives information about:
the x-value where the mouse pointer is at the moment, expressed in pixels on the chart canvas
the y-values for all the data series in closest position to the mouse x-value, expressed in the y-axis real-world unit (euros, kilograms, etc.)
It is necessary therefore to feed the custom tooltip also with y-axis mouse position information expressed in pixels on the chart canvas.
The tooltip can then calculate which data series is closest to the vertical mouse position and display only the value belonging to that data series.
Extracting the y-position in pixels is tricky, because Recharts changes the mapping between pixel and ordinate values each time it redraws the chart. But there is a chart component that must know very well this mapping, in order to place itself at the right vertical position and display the corresponding real-world ordinate value: that's every tick on the y-axis.
Problem is: how do we plug into the Recharts drawing workflow in order to get to know the mapping?
Here's how: the tick property of the Recharts YAxis component allows to provide a custom React component, albeit not documented with examples.
This custom component is instantiated one time for each tick that Recharts decides to place on the y-axis.
By trial and error I found out that my custom Tick component receives the following properties:
{ x, y, payload, ...anyCustomPropertyAddedByMe }
Where x and y are the cartesian coordinates of the tick (canvas pixels) and payload is such an object:
{ coordinates, isShow, offset, tickCoord, value }
Where value is expressed in real-world y-axis units.
The idea is to find out the couple (y, value) for the lowest and highest tick in each drawing and calculate the conversion factor between pixels and real values.
This will allow the custom tooltip to perform the computations mentioned above.
(Strictly speaking it would be enough to collect two couples from the first two ticks that are instantiated at each chart repaint, but choosing the two most far apart gives more precision)
The whole algorithm is divided among three components:
a tooltipCollector: this is a JavaScript module that presents two methods:
collect(value, y), invoked by the customized tick, that stores all couples (y, value) in a private array _collection
maxAndMin(), invoked by the custom tooltip, that reads the _collection array and returns the couple of items in the collection that represent the lowest and highest ticks (watch out that vertical pixel values in a canvas are measured upside down!)
a CustomizedTick React component that:
receives the tooltip collector among its custom properties
sends its y and payload.value to the collector by invoking its collect(y, value) method
returns a very simple JSX tick markup that makes usage of y (to place itself at the right vertical position) and payload.value (to display the user the real-world value the tick indicates)
a CustomTooltip React component that:
receives the tooltip collector among its custom properties and invokes its maxAndMin() method
verifies (by considering its prop coordinate.y) whether it's close enough to one of the chart data series, using a threshold value; this ensures that the tooltip is drawn only when the mouse cursor is very close to a point on the graph
modifies its returned JSX markup to contain only the value relative to the data series the mouse is closest to; in case more points in the chart are closer than the threshold, the tooltip will present more than one value
The code in my gist has been simplified to remove all unnecessary JSX markup. It presents a chart component that puts at work all the above mentioned components.
Please note that the standard Recharts behaviour of highlighting all the data series' points to which the tooltip abscissa is pointing has not been changed. It is therefore good practice to put a color code in the tooltip content to illustrate clearly to which data series the displayed value belongs.

PostGIS clipping raster with the same color band as the orignal raster

I am trying to clip a raster so that the clipped raster would have the same minimum and maximum values for the color band as the original raster.
For example if i clip the raster with this command:
create table clipped AS SELECT
ST_Clip(rast,ST_MakePolygon(ST_GeomFromText ('LINESTRING(424920
7370964,
424920 7371476,425432 7371476,425432 7370964,424920 7370964) ')) ) FROM original;
I get the following result:
So the clipped raster has band minium value as 0 and maxium value as 20. Instead of that, i want it to be exactly same as the 'original' raster: from 0 to 33.
I am new for PostGIS, but i have tried to find an answer for a while to this question but i haven't found anything. I have tried the functions like ST_Reclass but with no success. What is the proper way to do this with PostGIS?
Why is that happening?
The reason that your range changes is because your maximum value (33 in your case) is not contained within the area you clipped. This is not a bad thing, its just a fact. It's not a PostGIS thing, its just a clipping thing.
Can we find a solution?
I'm guessing that the real problem you want solved is that the two rasters look very different in QGIS. That's really easy to fix! I'll show you how with some example data.
Exmaple Data
Here's what we're starting with:
Link to image because I don't have enough rep to embed an image yet, I guess...
Double click on the "clipped" layer to open up the "Layer Properties" window and select the Style tab from the list on the left side of the window
Locate the text window for "Max" and change it to 33 to match your original raster. This picture may help. It's worth noting that you may run into a case where your Minimum is different in the clipped raster as well like it is here. You can adjust that in the same fashion.
Apply your changes and watch them work!

Is it possible to draw a 2-D plot on X11 display window using C?

I was working on displaying some of the 2-D plots on X11 display. For example, values of X in X-axis and corresponding sin(X) in Y-axis, which should be displayed on the display window.
The only idea I have right now is to use two XDrawLines() for X-Axis and Y-Axis. Next step would be using XDrawPoints() for the corresponding points. However, I am doubtful about perfect visualization of these points over the two axes. Next issue would be how to interpolate the points so that a curve comes into picture, like sin(X).

JFreeChart: Logarithmic Axis Tick Labels missing

I am using JFreeChart to make XYLineCharts with a Logarithmic y-axis but am facing an issue that I am unable to resolve.
My x, y values are very low in some cases (in one such case, the y-axis values for the dataset range between 4.5e-8 to 1.7). I plot these values on a XYLineChart using a Logarithmic Axis for the y-axis (and using LogAxis.createLogTickUnits(Locale.ENGLISH) and .setExpTickLabelsFlag(true) on the y-axis to create the exponential tick units). I set my range's bounds from 4.5e-8 to 1.7 and can see the points plotted clearly but there are no tick labels visible for the y-axis !
I was earlier having this issue while zooming into the charts but I have fixed the zoom & AutoZoom by over-riding those methods.
My current LogarithmicAxis works well for most of my x, y datasets but in a few cases, the y-axis is plotted but does not show any Tick Labels on it, despite my creating them & setting their visibility to true.
If anyone has any suggestions on how to fix this & ensure that the Tick Labels are visible no matter what the y-axis values may be, please let me know soon as I need to get this done ASAP.
Thanks.

Silverlight toolkit chart too many labels on axis

I'm using the newest chart control from silverlight toolkit to plot some data. For small cases it works ok, but for bigger samples the X axis labels overlap. It would be no problem if the chart would simply omit some of the values or I could specify to just show every 10th of them ...
I couldn't find any properties providing this behavior. Any ideas?
Assuming this is a Linear axis then you can specify the interval to use via the the Interval property on the axis.
If the axis in question is Category Axis then dropping some labels may not be valuable to the user. One option is to use the LayoutTransfomer to rotate the labels to an angle reducing the width needed for each one. See this Delay Blog on the subject.

Resources