Created
May 8, 2018 11:22
-
-
Save Peppe/e64e36090876fae715dac03fdd68273e to your computer and use it in GitHub Desktop.
Vaadin Charts where only last data point has a label
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jensjansson; | |
import com.vaadin.addon.charts.Chart; | |
import com.vaadin.addon.charts.model.*; | |
public class LastPointChart extends Chart { | |
public LastPointChart() { | |
Configuration conf = getConfiguration(); | |
setConfiguration(conf); | |
conf.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
PlotOptionsLine po = new PlotOptionsLine(); | |
conf.setPlotOptions(po); | |
DataLabels labels = new DataLabels(); | |
po.setDataLabels(labels); | |
labels.setEnabled(true); | |
labels.setAlign(HorizontalAlign.LEFT); | |
labels.setFormatter( | |
"function() { " + | |
" if(this.point.x == this.series.data.length - 1) { " + | |
" return this.y; " + | |
" } else { " + | |
" return null; " + | |
" } " + | |
"}" ); | |
labels.setCrop(false); | |
labels.setOverflow("false"); | |
ListSeries series1 = new ListSeries(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4); | |
ListSeries series2 = new ListSeries(106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5); | |
conf.addSeries(series1); | |
conf.addSeries(series2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment