Draw 2 lines with different labels in p:lineChart

UI Components for JSF
Post Reply
jpessoa
Posts: 13
Joined: 11 Jul 2022, 13:12

05 Aug 2022, 18:12

Hi,

Is it possible to draw, for example, one line with values (2,4), (1,2) and another one with (5,6),(7,8) using p:lineChart?

Thanks in advance,
Jorge Pessoa

jepsar
Posts: 86
Joined: 03 Sep 2014, 11:41
Location: NL / BE
Contact:

07 Aug 2022, 16:18

I don't see why not
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub: https://github.com/jepsar

jpessoa
Posts: 13
Joined: 11 Jul 2022, 13:12

08 Aug 2022, 11:24

For instance, in primefaces example
cartesianLinerModel = new LineChartModel();
ChartData data = new ChartData();

LineChartDataSet dataSet = new LineChartDataSet();
List<Object> values = new ArrayList<>();
values.add(20);
values.add(50);
values.add(100);
values.add(75);
values.add(25);
values.add(0);
dataSet.setData(values);
dataSet.setLabel("Left Dataset");
dataSet.setYaxisID("left-y-axis");
dataSet.setFill(true);

LineChartDataSet dataSet2 = new LineChartDataSet();
List<Object> values2 = new ArrayList<>();
values2.add(0.1);
values2.add(0.5);
dataSet2.setData(values2);
dataSet2.setLabel("Right Dataset");
dataSet2.setYaxisID("right-y-axis");
dataSet2.setFill(true);

data.addChartDataSet(dataSet);
data.addChartDataSet(dataSet2);

List<String> labels = new ArrayList<>();
labels.add("Jan");
labels.add("Feb");
labels.add("Mar");
labels.add("Apr");
labels.add("May");
labels.add("Jun");
data.setLabels(labels);
cartesianLinerModel.setData(data);

how can i draw 0.1 for Feb and 0.5 for Jun (values2.add(0.1); values2.add(0.5);) (labels.add("Feb");labels.add("Jun");)?

Thanks in advance,
Jorge Pessoa

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 24 guests