Is there a way in Vaadin 14 (or higher) to create what's called a "spectra" chart? Essentially, it's 99% identical to a "scatter" chart, except that a line is drawn from the point all the way down to the x-axis (please see figures 1 and 2 below which more or looks like a correct spectra chart.). I created a "hack" to achieve these quasi spectrum charts in Vaadin using "line charts" and by adding two "fake" points of intensity 0 to the left and to the right of my immediate point (as shown in code snippet below entitled "code snippet 1"). While my hack more-or-less works (pls see fig 1 image below), it causes a few problems: 1) it seems to make the lines appear more like bar-chart rectangles (please see fig 2) instead of points with narrow lines; 2) it seems to cause slight mistakes in the x-axis location. For example, in figure 2, the black line is to the left of the blue line; but in figure 3 (which is nothing more than the zoomed in perspective), it's to the right; and 3) it causes the x-axis to appear in the same color as the series, since my hack causes a line to appear to connect the fake right "0" of one point with the fake left "0" of the next point. (Plus, it means my chart has 3x the number of points than it needs to have, since I have two fake 0 points for every real point.)
Code snippet 1:
private void addTheSeries(DataSeries series, final float mz, final float intensity) {
//14.1.19
series.add(new DataSeriesItem(mz, 0));
series.add(new DataSeriesItem(mz, intensity));
series.add(new DataSeriesItem(mz, 0));
}
Figure 1:
Figure 2:
I'm using Vaadin 14.1.19 on Open jdk 11 and with Chrome on Chromebook as the browser.
I think it this case instead of using a Line type which is the default you'd benefit from using Column type. You can configure columns to be thin, configure zoomType and use axis configuration to get the extremes you want.
Chart chart = new Chart(ChartType.COLUMN);
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Spectrum example");
configuration.getChart().setZoomType(Dimension.XY);
DataSeries series = new DataSeries();
series.add(new DataSeriesItem(120, 5));
series.add(new DataSeriesItem(180, 50));
series.add(new DataSeriesItem(290, 350));
series.add(new DataSeriesItem(420, 500));
series.add(new DataSeriesItem(740, 450));
PlotOptionsColumn options = new PlotOptionsColumn();
options.setPointWidth(1);
series.setPlotOptions(options);
configuration.addSeries(series);
YAxis y = configuration.getyAxis();
y.setTitle("");
configuration.getLegend().setEnabled(false);
add(chart);
Result looks like this:
And the width is kept after zooming in:
Related
Earlier, I asked how to create "spectra" charts in Vaadin (see How to create a "spectrum" chart using Vaadin 14+). It turned out that one didn't actually need to create barcharts -- the only real need seemed to be to set the pointwidth to 1. (This solved the "very wide" widths lines when zooming.)
HOWEVER: I think there's a bug in vaadin charts when one has more than 1 series presents and when one zooms: the line moves to an inccorrect position on the x-axis (or the x-axis is no longer placed correctly.) Any thoughts on how to resolve? Here are two screenshots showing the problem. In the first one, only ONE series is visible and the line is at the correct x-axis point of ~598.36. In the second screenshot, though, (where the only change I have made is to enable the 2nd series), the line moves to an INCORRECT x-axis coordinate (it seems like it's ~598.25!!!).
One theory I have is that adding the second series somehow confuses the chart from determining the correct x-axes....maybe because each series has it's own x axis logic in some way? Not sure....(I'm using Vaadin 14 and I tested this both in my dev env and on production.)
is there any way to change the smoothing setting via config ?
https://github.com/highcharts/highcharts/blob/master/ts/parts-more/Polar.ts
line 190.
Or do I have to override some functions ? for info - I'm trying to change the interpolation and have got this far. If there is a better way to change the interpolation that would be an acceptable solution.
The problem I am trying to solve is where the interpolated area chart curves actually plot outside of the radar chart because the curvature is too large (ie when every value is at its maximum)
Many thanks
It is impossible to change this value via the config. You can report this idea here: https://github.com/highcharts/highcharts/issues - if core developers will see that this feature is needed they will implement it in the future.
For now, as a workaround, you can overwrite the whole function as a function with changed value.
Demo: https://jsfiddle.net/BlackLabel/j362zfpq/
Highcharts.Series.prototype.getConnectors = function(segment, index, calculateNeighbours, connectEnds) {
var i, prevPointInd, nextPointInd, previousPoint, nextPoint, previousX, previousY, nextX, nextY, plotX, plotY, ret,
// 1 means control points midway between points, 2 means 1/3 from
// the point, 3 is 1/4 etc;
smoothing = 1,
denom = smoothing + 1,
leftContX, leftContY, rightContX, rightContY, dLControlPoint, // distance left control point
dRControlPoint, leftContAngle, rightContAngle, jointAngle, addedNumber = connectEnds ? 1 : 0;
....
}
I know this can be done in d3 Sankey but I don't need anything that complex. I have my Highcharts sankey complete and all my formatting is done, save one thing.
The chart renders aligned along the centerline. I'd like to set it so that the entire sankey diagram is flat against the top border of the frame.
The first node will be flat against the top, and all other nodes and links will flow down from that point. I've searched here and on the Highcharts support sites, read the APIs, and consulted The Google but I have not turned up anything.
Since this is purely aesthetic it's not a showstopper if I can't do it but since I've now seen it done in d3, I'm hoping there is a Highcharts equivalent.
Thank you
See diagram for reference (ignore colors and link weights of course)see illustration
I've slightly edited the core code and achieved the desired result.
Live working example: http://jsfiddle.net/kkulig/dzdsjwbs/
I've overwritten Highcharts.seriesTypes.sankey.prototype.translate function and commented out two lines in these two code fragments:
1.
fromNodeTop = (
//column.top(factor) +
column.offset(node, factor)
),
2.
toY = (
//toColTop +
(toNode.offset(point, 'linksTo') * factor) +
nodeColumns[toNode.column].offset(
toNode,
factor
)
),
Introduction
I am using the TChart component and am finding the options rather confusing and hard to find what I need.
The Left Axis of the chart has a minimum of 0 and a maximum of 5000, the Bottom Axis has a minimum of 0 and a maximum of 52 (weeks in a year).
In my chart I have 2 series that are populated based on values from a record I have created which can be edited at runtime, everything is working good so far.
Problem
Take a look at the below image of part of the chart filled with some random values:
I am not sure if such an option exists or not, but notice from week 4 onwards where no values have been added there is a solid red line.
I don't want the chart to plot values that are less than 0, so in this example from week 4 onwards there should be no more lines (I can confirm that from week 4 onwards I have the values set at -1)
Week 1 to 4 does not show this bottom red line, obviously because the values are greater than 0 and are therefore plotted above the line, but this should make my problem a bit more clearer.
So, how do I prevent the chart from plotting / drawing values that are less than 0, importantly for the Bottom Axis of the chart?
I am sure there must be a simple option somewhere, I just cannot find it if there is one as I am not too familiar with the TChart Component.
You have the possibility when adding values to a series to add them as null.
This will prevent them from showing.
Ken is correct saying that a tricky situation is to handle a single value surrounded by null values.
Picking another series type than FastLine and show dots as well as lines might work better.
For a FastLine series to show gaps, set:
Series1.IgnoreNulls := False;
And to discriminate values below zero:
if (y < 0) then
Series1.AddNullXY(x, y, '')
else
Series1.AddXY(x, y, '');
if y < 0 then
LineSeries1.AddXY(x, y, '', clNone)
else
LineSeries1.AddXY(x, y, '', clRed);
I'm evaluating TChartProVCL for XE3.
I created 2 manual series:
1) Series1, a stair-step line
2) Series2, a simple line intersecting Series1 at various points
I then created a calculated series, X Cross Points, which should be the cross points of Series1 and Series2.
It looks fine, except at x=6, and x=5.6 (approx.) This looks like a bug to me.
My ultimate goal, FYI, is to color the regions inside the series. A TRegionBandTool would get close, but I need to color the areas above and below Series1 with different colors.
I'm afraid the TCrossPointsFunction doesn't support sources set with the Stairs mode.
I've added it to the wish list to be implemented in future releases.
In the case of using the "stair-step" series with the TCrossPointsFunction I've discovered a simple "cheat" that is good enough for my purposes. I merely:
Turn OFF the stair-step property.
Create the stair step effect by placing two points very close together on the X axis.
For example:
const
UPPER = 85;
LOWER = 75;
begin
SysThresh.Clear;
for i := 0 to 8 do
SysThresh.AddXY(i, UPPER);
SysThresh.AddXY(8.001, LOWER);
SysThresh.AddXY(12.999, LOWER);
for i := 13 to 25 do
SysThresh.AddXY(i, UPPER);
This gives me the stair step effect without confusing the TCrossPointsFunction.