d3fc - Candlestick multi-series Cartesian chart - d3fc

How can I render a multi-series, cartesian chart with candlesticks?
I have this currently:
http://blockbuilder.org/anonymous/af3258802b35d6dc327dc813eb4c32e0"
On line 63:
d3.select(nodes[i])
.select('svg')
.call(candlestickSeries);
The above works, but the following doesn't:
const multiSeries = fc.seriesSvgMulti()
.series([
candlestickSeries,
volumeSeries
])
const cartesianChart = fc.chartSvgCartesian(
xScale,
yScale
)
.plotArea(multiSeries);
...
d3.select(nodes[i])
.select('svg')
.call(multiSeries); //or .call(cartesianChart)
I need to render a candle chart + volume multi-series with gridlines. I can't find any examples of these things combined.

It's hard to determine what is wrong with your code, however, you might find the following example, which combines an OHLC series with volume, to be useful:
https://bl.ocks.org/ColinEberhardt/485ad09b7967e2a0f9bfe6e10192c26a

Related

Is there an R function that allows me to combine 2 graphs?

#I'm trying to do a taste wheel, like the Meilgaard wheel.
I'm not trying to do anything complex I only want to plot together a pie chart and a PCA plot.
I would like to have the piechart bigger than the PCA graph.
I would like to plot the pie graph with both the two PCA graphs or with the fviz_pca_biplot.
The following is the PCA:
principal4<-PCA(ExpertWine2,scale.unit = T,ind.sup = NULL,quanti.sup =29:30,quali.sup =1,graph = T,axes = c(1,2),ncp = 3)
fviz_pca_biplot(principal4)
The following is the pie chart:
slices <- c(10, 10, 10, 10)
lbls <- c("acidity", "freshness", "sweetness", "corposity")
coloris = c("gold", "cyan", "indianred1", "burlywood4")
cake=pie(slices, labels = lbls, init.angle=45, main="Pie Chart of tastes",col=coloris)
There are multiple packages aimed at solving this. It will depend on whether you as using a base r plotting implementation or something like ggplot.
I would reccomend looking at bentobox (strict positioning), patchwork (auto positioning) and cowplot (somewhere in the middle). Patchwork is primarily aimed at ggplot but the other two should work with any plotting method.
bento box:
https://github.com/PhanstielLab/BentoBox
patchwork:
https://patchwork.data-imaginist.com/
cowplot:
https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html

Is it possible to make VictoryPie Slices overlap on each other?

I'm using the Victory Pie in my React Native app and it renders fine without any issues, but my requirement is that each slice within the pie chart should be have circular corners and overlap on each other like in the image:
I'm able to get the circular corners by applying the attribute:
cornerRadius
but is it possible to make them overlap like in the picture or should I create a custom component?
Ran into same issue, here's my workaround:
You have to override Victory's data component and create an overlap by increasing endAngle a bit.
Example below also shows how to achieve circular shape of slices.
function CustomSlice(props: SliceProps) {
const { datum } = props;
const sliceOverride = {
...props.slice,
endAngle: (props.slice?.endAngle ?? 0) + 0.3,
};
return (
<Slice {...props}
slice={sliceOverride}
cornerRadius={50}
sliceStartAngle={datum.background ? 0 : props.sliceStartAngle}
sliceEndAngle={datum.background ? 360 : props.sliceStartAngle} />
);
}
/* ... */
<VictoryPie dataComponent={CustomSlice} />
Result for [2, 1, 1] data values:
This answer is quite late, but after a tone of searching the only solution I could find to this was to create a second <VictoryPie> graph and have it resting directly underneath the graph you are wanting the background color for.
This solution only worked for having a single background + color and not multiple like you required in your example though.

How to plot two data series on bar chart with separate range axes

I was wondering if it is possible to plot (XYPlot) a dataset in JFreeChart where the series contained in the dataset are plotted against separate y-axis ranges. The date is clustered by category/timestamp, e.g. if my dataset was this:
Timestamp Val1 Val2
2019-04-26 0.6 603
2019-04-25 2.1 1040
2019-04-24 4.1 255
It is impractical to plot both value series on the same range axis.
I've attempted extracting each series into its own dataset, so that I can call plot.mapDataSetToRangeAxis(); but when I add multiple datasets to the plot, the bars tend to render on top of each other. Perhaps I'm missing something simple?
There are a few posts that address separate elements of what I'm looking for, but think I need something that combines these two:
JFreeChart - XYBarChart Show Separate Bars for Each Series
Setting different y-axis for two series with JFreeChart
Here is the python code I'm currently using—inside inductive automation/ignition's reporting module; they allow you configure the JFreeChart prior to rendering.
def configureChart(chart):
from org.jfree.chart.axis import DateAxis
from org.jfree.data.xy import XYSeries, XYSeriesCollection
from org.jfree.chart.renderer.xy import ClusteredXYBarRenderer
from java.awt import Color
from java.text import NumberFormat
class mins_to_str(NumberFormat):
def format(self,*args,**kwargs):
r = ''
number = args[0]
hrs = number//60
mins = number%60
r = '%02i:%02i' %(hrs,mins)
if len(args)>1:
toAppendTo = args[1]
pos = args[2].getField()
r = toAppendTo.insert(pos,r)
return r
plt = chart.getPlot()
renderer = ClusteredXYBarRenderer
xax = DateAxis()
plt.setDomainAxis(xax)
for i in range(plt.getDatasetCount()):
d = plt.getDataset(i)
dsc = XYSeriesCollection()
series = XYSeries(d.getSeriesKey(0))
print('SERIES [%s]' %series)
for r in range(d.getItemCount(0)):
xv = d.getXValue(0,r)
yv = d.getYValue(0,r)
print(' X: %s (%s)' %(xv,type(xv)))
print(' Y: %s (%s)' %(yv,type(yv)))
series.add(xv,yv)
dsc.addSeries(series)
plt.setDataset(i,dsc) # assuming all of my series need to be in the same dsc for this to work...
plt.setRenderer(i,renderer)
if i > 0:
plt.mapDatasetToRangeAxis(i,1)
else:
plt.mapDatasetToRangeAxis(i,0)
plt.getRangeAxis(0).setNumberFormatOverride(mins_to_str())
Currently, I'm getting this:
Any ideas/help would be greatly appreciated.
Here is a time series chart within ignition's Report developing environment.
This one is completely setup using the Chart Options and just a tiny bit of JFreeChart scripting. Should be similar to designing a bar chart. Hope it helps.
JFreeChart Script -
#Import Java classes - Color & JFreeChart
from java.awt import Color
from org.jfree.chart.plot import CategoryPlot
#get Plot of Current Chart
plot = chart.getPlot()
#Set color of domain and range gridlines
plot.setDomainGridlinePaint(Color.black)
plot.setRangeGridlinePaint(Color.black)

anychart stock x-axis tick configuration. Change color and interval.

I've been scratching my head and reading the documentation a lot, trying to understand when using anychart stock how i can get control over the tick ( major/minor) display ? i.e i'd like to change the tick stroke color, the interval and make it rotate so text is vertical.
this is example data i'm playing with.
https://playground.anychart.com/sTrncP0D
Nothing special, i just want the major tick per minute and minor every 10 seconds if possible. I tried many variations but fail to get working combination and i think it's because the Stock axis differences.
Can you someone help how this is done ? Or if this is even possible.
thanks.
You can set ticks and minor ticks interval with the following lines:
var scale = chart.xScale();
scale.ticks([{major: {unit: 'minute', count: 1}, minor : {unit:'second', count: 10}}]);
You can rotate axis labels like this:
var labels = chart.plot().xAxis().labels();
minorLabels = chart.scroller().xAxis().minorLabels();
labels.rotation(90);
minorLabels.rotation(90);
You can adjust ticks appearance with the following lines:
var ticks = chart.plot().xAxis().ticks();
var minorTicks = chart.plot().xAxis().minorTicks();
ticks.stroke("red", 0.9);
minorTicks.stroke("blue", 0.9);

How to get xlab and ylab to work in mosaic plots in vcd package

For some reason I cannot get xlab and ylab to work in mosaic plots in vcd package.
I tried:
mosaic(~Sex +Survived,
data=Titanic,
shade=T,
legend=T,
main="myplot",
labeling_args=list(abbreviate = c( Sex=2, Survived=1)) ,
ylab="Gender",
xlab="survival")
this labels the axes "Sex" and "Survived" respectively.
mosaic(margin.table(Titanic, c(2,4)),
ylab="Gender",
xlab="survival",
shade=T, legend=T,
main="myplot",
labeling_args=list(abbreviate = c( Sex=2, Survived=1)))
this also labels the axes "Sex" and "Survived" respectively.
mosaicplot(margin.table(Titanic, c(2,4)),
shade=T,
legend=T,
main="myplot",
labeling_args=list(abbreviate = c(Sex=2, Survived=1)),
ylab="Gender",
xlab="survival")
this labels the axes correctly, but disregards ‘labeling_args’
Does anyone have any suggestions?
There is a huge part written on labels in the vcd documentation.
What you were looking for is this:
labeling_args = list(set_varnames = c(Sex="Gender", Survived="survival"))
It's been a while since you asked, but maybe it helps someone else ;)
The mosaic function and the mosaicplot function use very different graphic options. So it's no wonder that what works with one doesn't work with the other.

Resources