Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select dataset color #264

Closed
asmirn1 opened this issue Sep 23, 2020 · 7 comments
Closed

Select dataset color #264

asmirn1 opened this issue Sep 23, 2020 · 7 comments

Comments

@asmirn1
Copy link

asmirn1 commented Sep 23, 2020

It's probably not a bug. I just want to ask a question:

By default, the first dataset is drawn blue, the second is red, the third is green, etc. I would like to draw some of the datasets completely black/gray. I was able to change the color of markers with dataset.setDataStyle(), but I don't understand how to change the color of lines.

I've tried dataset.setStyle("-fx-stroke: black"), dataset.setStyle("strokeColor=black"), and dataset.addDataStyle(index, "strokeColor=black"), but nothing worked for me.

Here, I'm using DefaultDataSet and ErrorDataSetRenderer.

What is the correct way to change the color of a dataset?

@wirew0rm
Copy link
Member

Hey there, dataset.setStyle("strokeColor=black") should be the way to go. For a sample using this you can look for example at the DataSetFilterSample and try to find out where your setup differs. (The gaussian function in the sample is a DefaultErrorDataSet which should be the same as the DefaultDataSet for the styling).

I hope this helps and please let us know why it didn't work in the first place.

PS: If you want to different default colors, you can look at CustomColorSchemeSample which shows how to define your own color schemes for the plots.

@asmirn1
Copy link
Author

asmirn1 commented Sep 23, 2020

I've just tried dataset.setStyle("strokeColor=black") and it worked. Thank you!

An interesting thing is that, previously, I called both dataset.setStyle("strokeColor=black") and dataSet.addDataStyle(index, "strokeColor=black;") and it would give me an error.

Here is the code that works for me:

        DefaultDataSet dataSet = new DefaultDataSet(feature.toString());
        dataSet.setStyle("strokeColor=black");
        for (DataPoint dataPoint : chromatogram.getDataPoints()) {
            double retTime = dataPoint.getRetTime();
            double intensity = dataPoint.getIntensity();
            dataSet.add(retTime, intensity);
        }

However, if I add dataSet.addDataStyle(), then an error is thrown:

        DefaultDataSet dataSet = new DefaultDataSet(feature.toString());
        dataSet.setStyle("strokeColor=black");
        for (DataPoint dataPoint : chromatogram.getDataPoints()) {
            int index = dataSet.getDataCount();
            double retTime = dataPoint.getRetTime();
            double intensity = dataPoint.getIntensity();
            dataSet.add(index, retTime, intensity);
            dataSet.addDataStyle(index, "strokeColor=black;");
       }

Here is the error:

Caused by: java.lang.NoSuchMethodError: 'org.slf4j.spi.LoggingEventBuilder org.slf4j.Logger.atError()'
	at de.gsi.chart.utils.StyleParser.getColorPropertyValue(StyleParser.java:70) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.renderer.spi.ErrorDataSetRenderer.getDefaultMarker(ErrorDataSetRenderer.java:659) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.renderer.spi.ErrorDataSetRenderer.drawMarker(ErrorDataSetRenderer.java:608) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.renderer.spi.ErrorDataSetRenderer.drawErrorSurface(ErrorDataSetRenderer.java:508) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.renderer.spi.ErrorDataSetRenderer.drawChartCompontents(ErrorDataSetRenderer.java:736) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.renderer.spi.ErrorDataSetRenderer.lambda$render$3(ErrorDataSetRenderer.java:246) ~[chartfx-chart-11.1.5.jar:?]
	at java.util.Optional.ifPresent(Optional.java:176) ~[?:?]
	at de.gsi.chart.renderer.spi.ErrorDataSetRenderer.render(ErrorDataSetRenderer.java:240) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.XYChart.redrawCanvas(XYChart.java:439) ~[chartfx-chart-11.1.5.jar:?]
	at de.gsi.chart.Chart.layoutChildren(Chart.java:821) ~[chartfx-chart-11.1.5.jar:?]
	at javafx.scene.Parent.layout(Parent.java:1207) ~[javafx.graphics.jar:?]
	at org.dulab.adapbig.adapbigapp.uicomponents.charts.featurelistcharts.RetTimeIntensityChart.updateChart(RetTimeIntensityChart.java:87) ~[classes/:?]
	at org.dulab.adapbig.adapbigapp.uicomponents.tabs.SpectralDeconvolutionTab.updateCharts(SpectralDeconvolutionTab.java:45) ~[classes/:?]
	at org.dulab.adapbig.adapbigapp.uicomponents.tabs.AbstractFeatureListTab.lambda$new$0(AbstractFeatureListTab.java:77) ~[classes/:?]
	at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181) ~[javafx.base.jar:?]
	at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) ~[javafx.base.jar:?]
	at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74) ~[javafx.base.jar:?]
	at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102) ~[javafx.base.jar:?]
	at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:113) ~[javafx.base.jar:?]
	at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147) ~[javafx.base.jar:?]
	at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:105) ~[javafx.controls.jar:?]
	at javafx.scene.control.MultipleSelectionModelBase.lambda$new$0(MultipleSelectionModelBase.java:67) ~[javafx.controls.jar:?]
	at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:136) ~[javafx.base.jar:?]
	at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) ~[javafx.base.jar:?]
	at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:72) ~[javafx.base.jar:?]
	at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102) ~[javafx.base.jar:?]
	at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:114) ~[javafx.base.jar:?]
	at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:148) ~[javafx.base.jar:?]
	at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:69) ~[javafx.controls.jar:?]
	at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.updateSelectedIndex(TreeTableView.java:3326) ~[javafx.controls.jar:?]
	at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.select(TreeTableView.java:2853) ~[javafx.controls.jar:?]
	at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.select(TreeTableView.java:2827) ~[javafx.controls.jar:?]
	at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.selectFirst(TreeTableView.java:3248) ~[javafx.controls.jar:?]
	at org.dulab.adapbig.adapbigapp.uicomponents.tabs.AbstractFeatureListTab.readData(AbstractFeatureListTab.java:226) ~[classes/:?]
	at org.dulab.adapbig.adapbigapp.uicomponents.tabs.SpectralDeconvolutionTab.<init>(SpectralDeconvolutionTab.java:38) ~[classes/:?]
	... 62 more

It looks like I'm missing SLF4J dependency. But I do have log4j-core, slf4j-api, and log4j-slf4j-impl in my dependencies.

Here is a part of my pom.xml file:

         <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.13.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.30</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.13.3</version>
        </dependency>

@wirew0rm
Copy link
Member

This error is independent of styling, we are using slf4j-api in version 2.0.0-alpha0 with its new "fluent logging" api which is contrary to the statements in their manual not fully interoperable with older versions. Especially in combination with log4j this can lead to problems (see here). Short version: you need to update slf4j and log4j versions, slf4j 2.0 is a superset api, so all old code should continue working.

@asmirn1
Copy link
Author

asmirn1 commented Sep 23, 2020

Thank you for the explanation. I see that slf4j-api v2 is still in alpha, so I'd rather stay on version 1.7.30 for now. I'll just try to avoid any logging in ChartFX.

@asmirn1 asmirn1 closed this as completed Sep 23, 2020
@yezhengli-Mr9
Copy link

yezhengli-Mr9 commented Nov 20, 2023

I've just tried dataset.setStyle("strokeColor=black") and it worked. Thank you!

An interesting thing is that, previously, I called both dataset.setStyle("strokeColor=black") and dataSet.addDataStyle(index, "strokeColor=black;") and it would give me an error.

Here is the code that works for me:

        DefaultDataSet dataSet = new DefaultDataSet(feature.toString());
        dataSet.setStyle("strokeColor=black");
        for (DataPoint dataPoint : chromatogram.getDataPoints()) {
            double retTime = dataPoint.getRetTime();
            double intensity = dataPoint.getIntensity();
            dataSet.add(retTime, intensity);
        }

However, if I add dataSet.addDataStyle(), then an error is thrown:

        DefaultDataSet dataSet = new DefaultDataSet(feature.toString());
        dataSet.setStyle("strokeColor=black");
        for (DataPoint dataPoint : chromatogram.getDataPoints()) {
            int index = dataSet.getDataCount();
            double retTime = dataPoint.getRetTime();
            double intensity = dataPoint.getIntensity();
            dataSet.add(index, retTime, intensity);
            dataSet.addDataStyle(index, "strokeColor=black;");
       }

Dear @asmirn1, why use DefaultDataSet in your example?
my short term goal is simple: draw two CandleStickRenderer(...) together or draw two charts of eachCandleStickRenderer(...) separately and show two charts together; meanwhile, put some dots and short CandleStickRenderer(...)on each chart.

I try to get more insights about DefaultDataSet's role

in following

protected void prepareRenderers(XYChart chart, OhlcvDataSet ohlcvDataSet, DefaultDataSet indiSet) {
// create and apply renderers
var candleStickRenderer = new CandleStickRenderer(true);
candleStickRenderer.getDatasets().addAll(ohlcvDataSet);
var avgRenderer = new ErrorDataSetRenderer();
avgRenderer.setDrawMarker(false);
avgRenderer.setErrorStyle(ErrorStyle.NONE);
avgRenderer.getDatasets().addAll(indiSet);

while DefaultDataSet's role in following seems trivial:
protected void prepareRenderers(XYChart chart, OhlcvDataSet ohlcvDataSet, DefaultDataSet indiSet) {
// create and apply renderers
Renderer renderer = new CandleStickRenderer(true);
renderer.getDatasets().addAll(ohlcvDataSet);
chart.getRenderers().clear();
chart.getRenderers().add(renderer);
}

as well as

Instead of DefaultDataSet, I indeed see many examples using DefaultDataSet but DefaultDataSet not all the way the only DataSet appeared on examples.

while general declaration/ definition are here. Similar question is asked #527.

@wirew0rm
Copy link
Member

I'm not sure i understand the problem and how it is related to this issue. As explained in its javadoc, DefaultDataset is just a redirect/wrapper to DoubleDataSet at the moment, and it basically means that you don't care about the specific implementation of the dataset, so it could be exchanged in the future by a more general or more efficient implementation. The other DataSets used in the samples all have specific special behavior.
If you don't have any special requirements both DefaultDataSet and Double(Error)DataSet should work for you and the difference should not matter a lot.

Also please don't post your question to multiple long-closed issues, but rather open a new issue or in this case better a discussion thread as it does not seem to be a bug-report that we can solve in chartfx. You can always link to the issues from there. Also try to explain what you are trying to do.

@yezhengli-Mr9
Copy link

yezhengli-Mr9 commented Nov 20, 2023

I'm not sure i understand the problem and how it is related to this issue. As explained in its javadoc, DefaultDataset is just a redirect/wrapper to DoubleDataSet at the moment, and it basically means that you don't care about the specific implementation of the dataset, so it could be exchanged in the future by a more general or more efficient implementation. The other DataSets used in the samples all have specific special behavior. If you don't have any special requirements both DefaultDataSet and Double(Error)DataSet should work for you and the difference should not matter a lot.

Also please don't post your question to multiple long-closed issues, but rather open a new issue or in this case better a discussion thread as it does not seem to be a bug-report that we can solve in chartfx. You can always link to the issues from there. Also try to explain what you are trying to do.

Dear @wirew0rm ,
Thanks very much for the fast response~ Feel javadoc you mentioned should be somehow relevant to http://dbunit.org/apidocs/org/dbunit/dataset/DefaultDataSet.html (or relevant pages). I removed other "multiple long-closed“ question(s) and post in Q&A discussion #641 here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants