Style / remove axis overlap indicator in lightningChart js - charts

I would like to style axes in LightningChartJs and are not able to remove the little lines on axis overlap and the end of axis (Please see image below).
To set thickness of axis has no effect on the indicators:
const axisYStyles = axisYColors.map((color) => new SolidFill({ color }));
const axisYStrokeStyles = axisYStyles.map((fillStyle) => new SolidLine({ fillStyle, thickness: 1 }));
const axisX = this.chart.getDefaultAxisX()
.setStrokeStyle(axisYStrokeStyles[0]);
Would be nice if someone can help and explain how to remove or style this items. Thx in advance.

The little lines at the ends of the axis line are called "nibs". You can style and hide the nibs with Axis.setNibStyle().
emptyLine can be used to completely remove the axis and nib lines.
// Axis styling
chart.getDefaultAxisX()
// Hide the main axis line
.setStrokeStyle(emptyLine)
// Hide the Nib at the ends of the axis
.setNibStyle(emptyLine)
// Extract required parts from LightningChartJS.
const {
lightningChart,
emptyLine
} = lcjs
const chart = lightningChart()
.ChartXY()
// Axis styling
chart.getDefaultAxisX()
// Hide the main axis line
.setStrokeStyle(emptyLine)
// Hide the Nib at the ends of the axis
.setNibStyle(emptyLine)
chart.getDefaultAxisY()
// Hide the main axis line
.setStrokeStyle(emptyLine)
// Hide the Nib at the ends of the axis
.setNibStyle(emptyLine)
<script src="https://unpkg.com/#arction/lcjs#1.3.1/dist/lcjs.iife.js"></script>

Related

plotly: highlight (dim), rather than filter, when clicking on point in legend

I am building plotly figures with R. The figures have legends. Each legend has a colored point that represents a level of the data. Here is a minimal example:
library(plotly)
data(iris)
plot_ly(
x = ~Petal.Length, y = ~Petal.Width,
color = ~Species,
data = iris)
By default, double-clicking on a point in the legend completely hides all unrelated points. For example, double-clicking on the "versicolor" point in the legend hides all "setosa" and "virginica" points in the plot. In plotly argot, it "filters" the data in the plot.
But I would rather that clicking on a point in the legend highlight points in the plot. For example, I would like clicking (or double-clicking) on the versicolor point in the legend to dim the "setosa" and "virginica" points in the plot, perhaps by reducing their opacity. The versicolor points in the plot would then be "highlighted." Can this behavior be implemented?
I've read through the plotly documentation and searched SO and the plotly forums for related questions. That search suggests two potential solutions, but they seem rather complicated:
Write a custom "click event" function in JS. https://plotly.com/javascript/plotlyjs-events/#legend-click-events seems to suggest that this approach can work. I don't know whether I can implement this approach from R.
Disable the default legend (showlegend = FALSE), then create a new legend by adding traces that have customized click events.
Are these the best approaches? If they are, and if more than one is workable, which one should I pursue?
Other notes: I'm not using Shiny. And I know about the itemclick and itemdoubleclick legend attributes, and about highlight_key(), but they don't seem relevant. (Please correct me if I'm wrong.)
The key is to disable legend-click events in R, and then to write a custom event handler that changes the figure when plotly_legendclick is triggered. Here is an example:
library(plotly)
data(iris)
myPlot <- plot_ly(
x = ~Petal.Length, y = ~Petal.Width,
color = ~Species,
data = iris)
# Disable default click-on-legend behavior
myPlot <- layout(
myPlot,
legend = list(itemclick = FALSE, itemdoubleclick = FALSE))
# Add an event handler
onRender(
myPlot,
"function (el) {
const OPACITY_START = el._fullData[0].marker.opacity;
const OPACITY_DIM = 0.3;
el.on('plotly_legendclick', function (data) {
// Get current opacity. The legend bubble on which we click is given by
// data.curveNumber: data.curveNumber == 0 means that we clicked on the
// first bubble, 1 means that we clicked on the second bubble, and so on.
var currentOpacity = data.fullData[data.curveNumber].marker.opacity
if (currentOpacity < OPACITY_START) { // if points already dimmed
var update = { 'marker.opacity' : OPACITY_START }; // could also set to null
} else { // if points not already dimmed
var update = { 'marker.opacity' : OPACITY_DIM };
}
Plotly.restyle(el, update, data.curveNumber);
} );
}"
)
When a user clicks on a legend bubble, this code toggles the corresponding bubbles in the plot between "normal" and "dim" states.
To instead toggle the other bubbles in the plot -- that is, to modify the other traces -- a small modification will be needed. In particular, data.curveNumber is always the number of the trace that corresponds to the clicked bubble in the legend. To instead modify the other traces, we need to pass the other trace numbers to Plotly.restyle(), not the trace that is indexed by data.curveNumber. See the Plotly.restyle() documentation for more on this point.

Chartjs y axis getting cut off with long numbers

On Line and Vertical Bar charts on Chart.js, sometimes the values on the y-axis get cut off when the numbers are to long. See image below. I have only noticed this issue on these two graph types.
Image of y axis being cut off
You can fix that by setting the layout padding on the chart.
options: {
layout: {
padding: {
left: 10
}
}
}
Reference: http://www.chartjs.org/docs/latest/configuration/layout.html

How do I add a units label to a ILNumerics Colorbar

I would like to display the units in text for the values displayed on the colorbar. I have a colorbar added to my ILSurface and I'd like to show my units in text on the color bar along with the range.
Edit: I want to display text at the bottom of the color bar below the bottom tick just the one label.
I was able to get this to work this way
new ILColorbar()
{
Children = { new ILLabel("nm") {Position = new Vector3(.2f,.98f,0) } }
}
I have to say the Position coordinates are not very intuitive. I had to basically adjust the numbers by trial and error until it fit. I knew that the values range 0..1 so the X value was 1 at the bottom but I wanted it up from the border. And the Y value would need to be indented in some but I wasn't sure what was a good value but .2 works.
You can access the axis of ILColorbar and configure it in the usual way. Use the LabelTransformFunc on the ticks to set your own label text. You can use the default transform func and add your unit string.
Example:
var cb = scene.First<ILColorbar>();
cb.Axis.Ticks.LabelTransformFunc = (ind, val) =>
{
return ILTickCollection.DefaultLabelTransformFunc(ind, val) + "nm";
};
You can read more about the axis configuration here:
Axis Configuration
LabelTransformFunc in ApiDoc
Edit:
If only one label is needed, then add a new ILLabel object in ILColorbar group as follows:
new ILColorbar() {
new ILLabel("z(nm)") {
Position = new Vector3(0.5,1,0),
Anchor = new PointF(0.5f,0)
}
}
The ILColorbar area have the relative coordinates 0..1 over the width and the height of the color bar. So we set position x in the middle of the ILColorbar, and position y at the bottom.
The Anchor position is used as relative position in relation to the Position point.
ILLabel Documentation

How to format a minimalist chart with jFreeChart?

I generate a transparent chart that lets the background of a web page be seen through it.
So far I've done this (omited the populating of dataset for brevity):
lineChartObject=ChartFactory.createLineChart("Title","Legend","Amount",line_chart_dataset,PlotOrientation.VERTICAL,true,true,false);
CategoryPlot p = lineChartObject.getCategoryPlot();
Color trans = new Color(0xFF, 0xFF, 0xFF, 0);
lineChartObject.setBackgroundPaint(trans);
p.setBackgroundPaint(trans);
for (int i=0;i<=3;i++){
lineChartObject.getCategoryPlot().getRenderer().setSeriesStroke(i, new BasicStroke(3.0f));
lineChartObject.getCategoryPlot().getRenderer().setBaseItemLabelsVisible(false);
}
Which renders this:
I cannot find a way of:
Removing border of plot (1)
Removing border of leyend as well as making it transparent (3)
Making the labels on the X axis (2) to behave intelligently as the labels of Y axis do (A). Labels of Y axis space themselves so as to not clutter the graph, for example if I rendered the graph smaller, it would show fewer labels, like this:
Edit: X label domain is dates.
For (1) try:
plot.setOutlineVisible(false);
For (2), a common reason for having too many categories along the x-axis is that the data is actually numerical, in which case you should be using XYPlot rather than CategoryPlot. With XYPlot, the x-axis scale adjusts in the same way that the y-axis does.
Edit from OP: Using a TimeSeriesChart with a TimeSeriesCollection as XYDataSet did the work! (fotgot to say X domain is dates)
For (3) try:
LegendTitle legend = chart.getLegend();
legend.setFrame(BlockBorder.NONE);
legend.setBackgroundPaint(new Color(0, 0, 0, 0));

Why sometimes the bars with bar or hist have no border?

I noticed that sometimes, when I plot the bars using the functions bar() or hist(), the bars plotted have no border. They are a little bit less nice to see, and I would prefer the border or a little bit of space between them.
The figure shows what I got now, plotting three different datasets. The third graph is zoomed in order to show the lack of space between bars.
I get there this has something to do with the 'histc' parameters in bar function. Without the histc parameters the bars have some space between each others, but then the bar will be centered on the edges values, whereas I want the edges values to be, well, EDGES of each bar.
This is (the relevant part of) the code I used:
[...]
if edges==0
%these following lines are used to take the min and max of the three dataset
maxx=max(cellfun(#max, reshape(data,1,size(data,1)*size(data,2))));
minn=min(cellfun(#min, reshape(data,1,size(data,1)*size(data,2))));
edges=minn:binW:maxx+binW;
end
[...]
y{k}=histc(data{r,c}, edges);
bar(edges,y{k} , 'histc');
[...]
I think if you change the color of your bar plots you'll see that there actually is a border it just doesn't show up very well. You can also change the width of the bars so that they are more distinct.
% something to plot
data = 100*rand(1000,1);
edges = 1:100;
hData = histc(data,edges);
figure
subplot(2,1,1)
h1 = bar(edges,hData,'histc');
% change colors
set(h1,'FaceColor','m')
set(h1,'EdgeColor','b')
% Change width
subplot(2,1,2)
h1 = bar(edges,hData,0.4,'histc');
The EdgeColor and LineWidth properties of the Barseries object control the bar outlines. Try using the code and playing with the red, green, blue, and width values to get a better result.
red = 1;
green = 1;
blue = 1;
width = 3;
h = bar(edges,y{k} , 'histc');
set(h,'EdgeColor',[red green blue],'LineWidth',width);