the date in axis is presently showing with time. How can i format in only date like dd-MM-yy. As per echart for ‘time’ type axis a formatter like formatter: '{yyyy}-{MM}-{dd}' // gets labels like '2020-12-02' should work, but it is not working for me.
chart1.addXAxis(new XAxis().withAxisLabel(new AxisLabel().withFormatter("{dd}-{MM}-{yy}")));
Am I missing something. Please advice.
d.kremnev
(Dmitriy Kremnev)
August 15, 2024, 6:36am
3
Hi!
The ECharts formatter for the time axis type works for me. Can you share a test project that reproduces the problem?
Regards,
Dmitriy
I am using following code -
Chart chart1 = uiComponents.create(Chart.class);
BarSeries bar = new BarSeries();
chart1.addSeries(bar);
chart1.addXAxis(new XAxis().withAxisLabel(new AxisLabel().withFormatter("{dd}-{MM}-{yy}")));
chart1.addYAxis(new YAxis().withAxisLabel(new AxisLabel().withFormatter("{value}")));
chart1.setTitle(new Title().withText("Observation By Time"));
chart1.withTooltip(new Tooltip());
chart1.setWidth("100%");
chart1.setHeight("100%");
chart1.setDataSet(
new DataSet().withSource(
new DataSet.Source<EntityDataItem>()
.withDataProvider(new ContainerChartItems<>(bBSObservationsDc))
.withCategoryField("date")
.withValueFields("totalUnsafe")
)
);
The result i am getting -
Here category file is date type.
Am I missing something? Please give code of time formatter which is working.
Thanks
d.kremnev
(Dmitriy Kremnev)
August 15, 2024, 11:54am
6
The XAxis object has a AxisType#CATEGORY type by default. Formatting is only applied to axes with a AxisType#TIME type.
In your case it should be:
new XAxis().withType(AxisType.TIME)
.withAxisLabel(new AxisLabel().withFormatter("{dd}-{MM}-{yy}"));
Adding axistype to time cause blank chart.
I am getting data from data container and the date attribute is of date datatype. Is this causing problem?
Attaching test project
untitled.zip (105.8 KB)
d.kremnev
(Dmitriy Kremnev)
August 19, 2024, 7:51am
9
Hi!
I created an issue to fix this problem: Date datatype can't be formatted for Axes · Issue #3620 · jmix-framework/jmix · GitHub
As a temporary workaround you can try to use LocalDate datatype.
Regards,
Dmitriy