Why are the bars of my p:chart overlapping - jsf

Developing a Java8 application with jsf and primefaces, I encountered a small issue with the bar of my barChart which are overlapping. So my question is: How can I configure the width of the chart without impacting the interval of the axis?
My first idea was to modify the axis with xAxis.setTickInterval(); but the problem is that my axis is a DateAxis in month/year and it showed multiple times the same month in the axis (not multiple time the bar (cf the screenshot) reducing the overlapping).
And the code:
private void createChart() {
globalGradeEvolution = new BarChartModel();
globalGradeEvolution.setTitle("Evaluation globale");
globalGradeEvolution.setLegendPosition("e");
//Define two axis
Axis yAxis = globalGradeEvolution.getAxis(AxisType.Y);
DateAxis xAxis = new DateAxis("Dates");
//cacteristics of x axis
xAxis.setTickAngle(-30);
xAxis.setMax(LocalDate.now().getYear()+"-"+LocalDate.now().getMonthValue()+"-"+"15"); // middle of the month
xAxis.setTickFormat("%m/%Y"); // example: 08/2018
//cacteristics of y axis
yAxis.setLabel("Notes");
yAxis.setMin(min);
yAxis.setMax(10);
yAxis.setTickFormat("%.1f");
globalGradeEvolution.getAxes().put(AxisType.X, xAxis);
}
<h:form>
<p:chart type="bar" model="#{statChartView.globalGradeEvolution}" style="height:400px" responsive="true"/>
</h:form>

This is a bug in PrimeFaces + JqPlot combination.
The bug has been reported to PrimeFaces here: https://github.com/primefaces/primefaces/issues/3684

Related

Having both X and Y axes' Scales in Altair respond to a selection interval

I'm bringing this question from Altair's github. (https://github.com/altair-viz/altair/issues/2456) Is there a way to get the Scale on Y-axis in the bottom chart to respond to the selection brush? I'd like to be able to pan around the top chart with a selection and see the zoomed-in results in the bottom chart. If I uncomment the alt.Y, then both the X and Y axes show Years and it's messed up. Is there a way to pass just an X or Y value in the 'brush' maybe? Thank you very much!
brush = alt.selection_interval(init={'x':[1950, 1970], 'y':[1500000, 2500000]}, encodings=['x', 'y'])
base = alt.Chart().mark_line().encode(
x=alt.X('Year:Q', title=None),
y='Deaths:Q',
color='Entity:N'
)
alt.vconcat(
base.add_selection(brush).encode().properties(height=150, width=150),
base.encode(
alt.X('Year:Q', scale=alt.Scale(domain=brush)),
#alt.Y('Deaths:Q', scale=alt.Scale(domain=brush)) # (un)commenting this line makes it work/fail only along the x-axis
).properties(
height=500, width=500
),
data='https://vega.github.io/vega-datasets/data/disasters.csv'
)
Yes, see Open the Chart in the Vega Editor
It filters the data of the 2nd chart using a filter transform on the brush param.

How to render end ticks always using d3 svg axis

I am not sure how the tick placement works with d3 svg axis. I tried playing with the ticks, tickSize options but essentially I get the start and end ticks "sometimes" with random data plotted
http://plnkr.co/edit/i5DBgfWzr2sa8Yugg2A8?p=preview
(Please ignore the angularjs aspect. The part that I am interested in is the following in d3)
var make_x_axis = function () {
return d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(5)
.tickFormat("")
.tickPadding(8);
};
var make_y_axis = function () {
return d3.svg.axis()
.scale(y)
.ticks(6)
.orient("left")
.tickSize(10,10)
.tickPadding(8);
};
How do I always get the start and end ticks rendered for both X and Y axis? I clearly always get the start and end tick lines on both X and y axis (Unsure how that is happening - I do not see a .tick element at that location in the chrome inspector) but the labels are missing. I can find the first and last tick and render a text with the tick label info but clearly I cannot always do it because sometime the axis gives me the start ticks and sometime it does not.
Any help is appreciated.
Thank you
I am not sure I fully understand your question, if you want to remove the ending x-axis ticks, you should set
d3js V3
.outerTickSize(0),
d3js V4 - V6
tickSizeOuter(0)
If you want to customize the ending ticks, you may use
.tickValues(y.ticks(5).concat( y.domain() ));
Have a look at my JSFiddle for a demonstration.

JavaFx logarithmic Axis in BarChart

I need a logarithmic y-axis in a JavaFx BarChart. I tried use this
implementation of a valueAxis .
That code seems to be correct and it works in a lineChart as a x-axis.
However it works not in a BarChart, there are simply no bars in the plot. The valueAxis should work in any kind of chart, so I think the BarChart is the problem. But I can not find the bug.
Here is my code, how I tested the chart:
LogarithmicAxis yAxis = new LogarithmicAxis();
yAxis.setMinorTickVisible(true);
yAxis.setVisible(true);
yAxis.setLabel("label");
chart = new BarChart<String, Number>(xAxis, yAxis);
chart.setAnimated(false);
Series<String, Number> aSeries = new Series<String, Number>();
aSeries.getData().add(new XYChart.Data("test1", Math.log(90)));
aSeries.getData().add(new XYChart.Data("test2", Math.log(100)));
answer = FXCollections.observableArrayList();
answer.addAll(aSeries);
chart.getData().addAll(answer);
chartFxPanel.setScene(new Scene(chart));
chart.layout();

Displaying decimal places on primefaces pie chart

I would like to check how do I display decimals for primefaces ver 3.3 pie chart label?
Currently, there are two proportions in my chart. Label A and Label B. Label A has a very big number like 100000 but label B has 100. Therefore, in the pie chart, Label A is not 100%. However, primefaces converts this to 100% which is wrong. Is there any way I can show the decimal places instead of whole numbers as labels on the pie chart?
Define an extender function like:
function ext() {
this.cfg.seriesDefaults.rendererOptions.dataLabelFormatString = '%.4s%%';
this.cfg.seriesDefaults.rendererOptions.dataLabelThreshold = 0;
}
This will format your output labels to show percentage up to 4 digits after the decimal point. Also jqPlot by default, for areas smaller than 3% won't display any labels. You have to overwrite this value with dataLabelThreshold = 0.
Finally attach this extender function on your p:pieChart:
<p:pieChart id="sample" value="#{testClazz.pieModel}"
extender="ext" showDataLabels="true"/>
Define an extender function like:
function ext() {
this.cfg.seriesDefaults.rendererOptions.dataLabelFormatString = '%#.4f';
this.cfg.seriesDefaults.rendererOptions.dataLabelThreshold = 0;
}
in my case '%.4s%%' (PF 4.0) is not working so instead of I used'%#.4f' that work fine.

Fix Bar Chart Width and Spacing between bars in JFreeChart

I have stacked bar chart in which the number of columns is dynamic, can change from 1 to n columns. I want the spacing between the charts and width of the bar to be consistent. How do I fix it. Please suggest solutions / ideas.
In a Stacked Bar chart, you can change the spacing between bars using
CategoryAxis.setLowerMargin
CategoryAxis.setMargin and
CategoryAxis.setUpperMargin
Code is below
protected JFreeChart generateGraph() {
CategoryAxis categoryAxis = new CategoryAxis("Categories");
categoryAxis.setLowerMargin(.01);
categoryAxis.setCategoryMargin(.01);
categoryAxis.setUpperMargin(.01);
categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
ValueAxis valueAxis = new NumberAxis("Values");
StackedBarRenderer renderer = new StackedBarRenderer();
renderer.setBarPainter(new StandardBarPainter());
renderer.setDrawBarOutline(false);
renderer.setShadowVisible(false);
renderer.setBaseItemLabelsVisible(true);
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
CategoryPlot plot = new CategoryPlot( _dataset,
categoryAxis,
valueAxis,
renderer);
plot.setOrientation(PlotOrientation.VERTICAL);
JFreeChart chart = new JFreeChart( "Title",
JFreeChart.DEFAULT_TITLE_FONT,
plot,
true);
//ChartFactory.getChartTheme().apply(_chart);
return chart;
}
StackedBarRenderer devotes some effort to making the "spacing between the [bars] and width of the bar to be consistent." It's not clear what you want it to do differently as the number of columns changes. The relevant geometry is determined by the parent BarRenderer in such methods as calculateBarWidth(), which can be overridden as desired. Also, verify that there is a value for each category in each series.

Resources