use of io.jmix.charts.model.axis.CategoryAxis in project jmix by jmix-framework.
the class ChartsSerializationTest method testSerialChart.
@Test
public void testSerialChart() throws IOException, URISyntaxException, ParseException {
DataProvider dataProvider = new ListDataProvider();
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "1", "date", "2012-07-27", "value", 13)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "2", "date", "2012-07-28", "value", 11)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "3", "date", "2012-07-29", "value", 15)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "4", "date", "2012-07-30", "value", 16)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "5", "date", "2012-07-31", "value", 18)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "6", "date", "2012-08-01", "value", 13)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "7", "date", "2012-08-02", "value", 22)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "8", "date", "2012-08-03", "value", 23)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "9", "date", "2012-08-04", "value", 20)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "10", "date", "2012-08-05", "value", 17)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "11", "date", "2012-08-06", "value", 16)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "12", "date", "2012-08-07", "value", 18)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "13", "date", "2012-08-08", "value", 21)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "14", "date", "2012-08-09", "value", 26)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "15", "date", "2012-08-10", "value", 24)));
dataProvider.addItem(new MapDataItem(ParamsMap.of("id", "16", "date", "2012-08-11", "value", 29)));
AbstractChart chart = new SerialChartModelImpl().setCategoryField("date").setDataProvider(dataProvider).addValueAxes(new ValueAxis().setAxisAlpha(0.0).setPosition(Position.LEFT)).addGraphs(new Graph().setId("g1").setBullet(BulletType.ROUND).setBulletBorderAlpha(1.0).setBulletColor(Color.WHITE).setBulletSize(5).setHideBulletsCount(50).setLineThickness(2).setTitle("Red line").setValueField("value")).setCategoryAxis(new CategoryAxis().setDashLength(1).setMinorGridEnabled(true).setPosition(Position.TOP)).setChartScrollbar(new Scrollbar().setGraph("g1").setScrollbarHeight(30)).setChartCursor(new Cursor().setCursorPosition(CursorPosition.MOUSE).setPan(true)).setExport(new Export());
ChartSerializer serializer = getTestSerializer();
String json = serializer.serialize(chart);
String expected = readFile("SerialChart.json");
assertEquals(prettyJson(expected), prettyJson(json));
}
use of io.jmix.charts.model.axis.CategoryAxis in project jmix by jmix-framework.
the class CustomChartImpl method setupSerialChartDefaults.
protected void setupSerialChartDefaults(AbstractSerialChart chart) {
CategoryAxis categoryAxis = chart.getCategoryAxis();
if (categoryAxis == null) {
categoryAxis = new CategoryAxis();
chart.setCategoryAxis(categoryAxis);
}
String firstDayOfWeek = messages.getMessage("amcharts.firstDayOfWeek");
if (categoryAxis.getFirstDayOfWeek() == null) {
categoryAxis.setFirstDayOfWeek(DayOfWeek.valueOf(firstDayOfWeek));
}
if (StringUtils.isEmpty(chart.getDataDateFormat())) {
chart.setDataDateFormat(ChartJsonSerializationContext.DEFAULT_JS_DATE_FORMAT);
}
if (StringUtils.isEmpty(chart.getBalloonDateFormat())) {
String format = messages.getMessage("amcharts.serialChart.balloonDateFormat");
chart.setBalloonDateFormat(format);
}
}
use of io.jmix.charts.model.axis.CategoryAxis in project jmix by jmix-framework.
the class AbstractSerialChartLoader method loadComponent.
@Override
public void loadComponent() {
super.loadComponent();
loadConfiguration(resultComponent, element);
String byDate = element.attributeValue("byDate");
if (StringUtils.isNotEmpty(byDate)) {
if (resultComponent.getCategoryAxis() == null) {
resultComponent.setCategoryAxis(new CategoryAxis());
}
resultComponent.getCategoryAxis().setParseDates(Boolean.valueOf(byDate));
}
}
Aggregations