I'm using JSF2 and PrimeFaces 5.1.
My problem is that I don't know how to put dates in the Y axis of my graph. It only accepts Number types.
/**
* Graph's definition
* @return LineChartModel
* @throws ParseException
*/
public LineChartModel createLineModels() throws ParseException {
LineChartModel lineChartModel = new LineChartModel();
lineChartModel = initCategoryModel();
lineChartModel.setTitle("Graph's title");
lineChartModel.setLegendPosition("nw");
lineChartModel.getAxes().put(AxisType.X, new CategoryAxis("PV"));
Axis yAxis = this.lineChartModel.getAxis(AxisType.Y);
yAxis.setTickInterval("1");
yAxis.setLabel("Provisional dates");
return lineChartModel;
}
/**
* Initialization of the graph
* @return LineChartModel
* @throws ParseException
*/
public LineChartModel initCategoryModel() throws ParseException {
LineChartModel model = new LineChartModel();
ChartSeries provisionalDates= new ChartSeries();
provisionalDates.setLabel("Dates");
//Here, I set my data in the Graph
//In x-axis the date and the y-axis a numerical value
provisionalDates.set("2016-01-01", 5);
provisionalDates.set("2016-01-15", 8);
model.addSeries(provisionalDates);
return model;
}
My issue are those lines:
provisionalDates.set("2016-01-01", 5);
provisionalDates.set("2016-01-15", 8);
The method set only accept a Numerical value. I want to have date instead.
Do you know a way so I can put my dates in the Y axis?
Thanks
I finally found an answer with jqPlot.
The method set only accept a numerical value so what I did is to convert my date in milliseconds.
Then, you can add an extender to your chart with PF. The extender allows you to configure your chart:
After that, you just need to make the extender function:
The convertDate function only convert a getTime to dd/mm/yyyy.