pepstock-org / Charba

J2CL and GWT Charts library based on CHART.JS
https://pepstock-org.github.io/Charba-Wiki/docs
Apache License 2.0
62 stars 6 forks source link

Scatter Dataset ShowLine forced False #36

Closed elatoskinas closed 5 years ago

elatoskinas commented 5 years ago

In Chart.js, sometimes it is more convenient to simply pass x & y values (instead of configuring string-based labels), and enable the show lines option to use a Scatter Chart as a Line Chart. In fact, this approach has been typically recommended in Stack Overflow posts, such as this one.

However, Charba forces ShowLine to be false for ScatterDataSet.

Was this intended, or was this simply a temporary placeholder?

stockiNail commented 5 years ago

@lightingft I checked the post and the sample written teher is already available by Charba. In a Line chart you can use DataPoint (not only for timeseries). See here. Here a sample:

LineDataset dataset1 = chart.newDataset();
dataset1.setLabel("dataset 1");

IsColor color1 = Colors.ALL[0];

dataset1.setBackgroundColor(color1.toHex());
dataset1.setBorderColor(color1.toHex());
dataset1.setFill(false);
double[] values = getRandomDigits(months);

DataPoint[] dp = new DataPoint[months];
for (int i=0; i<months; i++) {
    dp[i] = new DataPoint();
    dp[i].setX(i);
    dp[i].setY(values[i]);
}
dataset1.setDataPoints(dp);

Here the result:

linedp

About the showLine, it has been set to false because the scatter charts usually don't draw the line among points. But, being Line chart equals to a Scatter one, you can use Line chart when needed.

What do you think?

elatoskinas commented 5 years ago

@stockiNail Thanks for the response. I indeed followed a similar method that you showed for creating a Line Chart, and it worked nicely.

However, it still seemed rather odd to me that no matter what value is passed into the Scatter Data Set show line method, the value is forced to false, causing confusion at first as to why the method does not work when first using it.

Also, I think there are certain types of graphs that can be made with the Scatter Chart, but not with the Line Chart, where the point connection does not exactly follow the typical continuous Line Chart format. Here is an example posted in a Stack Overflow question.

stockiNail commented 5 years ago

@lightingft yeah! I'll remove the overrided method in order that you can set the value that you want.

By default, it will be set to false. make sense?

elatoskinas commented 5 years ago

@lightingft yeah! I'll remove the overrided method in order that you can set the value that you want.

By default, it will be set to false. make sense?

Excellent! That is a nice change indeed.

stockiNail commented 5 years ago

Commited into master