Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Chart - Time field as category field displaying default date 01-01-1970
kevinkris
Hi All,
I had created a chart report which has a Time Field (Only time not date time) as category field. The values that are supplied to this field is only time. For example, 02:30:30, 00:00:05 etc.
But when the chart is displayed, the X series has default date of Java and Java Script 01-01-1970 is displayed before the time.
How can we remove the default date?
Please find attached chart for example. Interestingly the same value is working fine in the tooltip.
Code in rptdesign file of DataDefinition:
<DataDefinition>
<Definition>row["Time Field"]</Definition>
</DataDefinition>
Thanks for your comments.
Find more posts tagged with
Comments
mwilliams
Hi kevinkris,
You can format the x-axis labels in the chart editor under the x-axis section of the format chart tab.
kevinkris
Hi Michael,
Thanks for the quick response.
Since we generate rptdesign file we will have to use API.
Your fix work for ChartWithoutAxis but for ChartWithAxes it's not working.
Any idea? May be my code is not correct.
setTimeFormat(chartItem, "HH:mm:ss");
public void setTimeFormat(Chart cm, String dateFormat) {
if(cm instanceof ChartWithAxes) {
Axis baseAxis = ((ChartWithAxes) cm).getAxes().get(0);
SeriesDefinition baseSeries = baseAxis.getSeriesDefinitions().get(0);
baseSeries.setFormatSpecifier(JavaDateFormatSpecifierImpl.create(dateFormat));
} else if(cm instanceof ChartWithoutAxes) {
SeriesDefinition valueSeries = ((ChartWithoutAxes) cm).getSeriesDefinitions().get(0);
valueSeries.setFormatSpecifier(JavaDateFormatSpecifierImpl.create(dateFormat));
}
}
mwilliams
kevinkris
Do you get an error for the chart with axes?
kevinkris
Hi Michael,
Thanks for the response. I don't see any error. But the formatting is not done for charts with axis.
I think the code to get axis is not correct?
We need to fix this i guess:
Axis baseAxis = ((ChartWithAxes) cm).getAxes().get(0);
SeriesDefinition baseSeries = baseAxis.getSeriesDefinitions().get(0);
mwilliams
You could try getPrimaryBaseAxes()[0] rather than getAxes().get(0). I've seen this used in code around trying to get the base axis. Worth a shot.
kevinkris
Tried this code also and it's not working:
Axis xAxis = chart.getPrimaryBaseAxes()[0];
xAxis.getSeriesDefinitions().get(0).setFormatSpecifier(JavaDateFormatSpecifierImpl.create(dateFormat));
kevinkris
Finally fixed it for Axis charts also:
Only change is directly apply format to Axes itself.
No need to set it on SeriesDefinition as in the case of chart without axis.
Here is the code:
Chart cm;
if(cm instanceof ChartWithAxes) {
ChartWithAxes chart = (ChartWithAxes) cm;
chart.getAxes().get(0).setFormatSpecifier(JavaDateFormatSpecifierImpl.create(dateFormat));
} else if(cm instanceof ChartWithoutAxes) {
SeriesDefinition valueSeries = ((ChartWithoutAxes) cm).getSeriesDefinitions().get(0);
valueSeries.setFormatSpecifier(JavaDateFormatSpecifierImpl.create(dateFormat));
}