Duplicated color and marker shape after removing and adding series

Đang mở
#1,053 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
67/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
data-visualization

Hướng nghiên cứu

Start by tracing XYChart.removeSeries and XYChart.addSeries, then inspect how the chart assigns colors and marker shapes when a series is added. Reproduce the sequence in the issue with series A, B, C, then remove A and B while adding D and E. Done means C, D, and E retain distinct colors and marker shapes after repainting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug
Removing any serie except last from XYChart and adding that one serie once again or any other serie causes duplication of color and marker shape with original last serie.

To Reproduce
Steps to reproduce:
Create XYChart.
Add series A,B, C
Repaint chart.
Remove serie A
Add serie D
Repaint chart
Remove serie B
Add serie E
Repaint chart.
Result: All series C, D, E have the same color and marker shape - incorrect.

Sample chart code:

package example;

import java.awt.BorderLayout;
import java.text.ParseException;

import javax.swing.JFrame;

import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;

public class XChartBugDuplicatedColorAndMarker extends JFrame{

    private static final long serialVersionUID = 1L;
    
	double[] xValuesA = new double[] {10, 20, 30};
    double[] yValuesA = new double[] {10, 20, 30};

    double[] xValuesB = new double[] {11, 21, 31};
    double[] yValuesB = new double[] {10, 20, 30};
    
    double[] xValuesC = new double[] {12, 22, 32};
    double[] yValuesC = new double[] {10, 20, 30};

    double[] xValuesD = new double[] {13, 23, 33};
    double[] yValuesD = new double[] {10, 20, 30};

    double[] xValuesE = new double[] {14, 24, 34};
    double[] yValuesE = new double[] {10, 20, 30};

	private XYChart chart;
	XChartPanel<XYChart> chartPanel;
	
	public static void main(String[] args) throws ParseException {
		XChartBugDuplicatedColorAndMarker app = new XChartBugDuplicatedColorAndMarker();
		app.setSize(600,400);
		app.setVisible(true);
		
		app.replaceSeries();
	}

	public void replaceSeries() {
		
		Runnable r = new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(2000);
					
					chart.removeSeries("A");
					chart.addSeries("D", xValuesD, yValuesD);
					chartPanel.repaint();;
					
					Thread.sleep(2000);
					
					chart.removeSeries("B");
					chart.addSeries("E", xValuesE, yValuesE);
					chartPanel.repaint();
				}
				catch(InterruptedException ie) {
					return;
				}
			}
		};
		new Thread(r).start();
	}

	public XChartBugDuplicatedColorAndMarker() {
		chart = getXYChart();
		chartPanel = new XChartPanel<>(chart);
		setLayout(new BorderLayout());
		add(chartPanel, BorderLayout.CENTER);
	}
	
	public  XYChart getXYChart() {
		XYChart chart =
			new XYChartBuilder()
				.width(720)
				.height(480)
				.title("Duplicated color and marker shape after remove and add serie")
				.xAxisTitle("Count")
				.yAxisTitle("Value")
				.build();

		chart.addSeries("A", xValuesA, yValuesA);
		chart.addSeries("B", xValuesB, yValuesB);
		chart.addSeries("C", xValuesC, yValuesC);

		return chart;
	}
}

Screenshots
Before removing and adding series:
obraz

After removing and adding series (duplicated colors and marker shapes for D and E - the same as for C):
obraz

Expected behavior
Series C, D, E have different colors and marker shapes

Ngôn ngữ chính
Java
Star
1.6k
Fork
400
Merge trung bình
3 ngày 9 giờ
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của knowm/XChart

Tất cả issue của knowm/XChart

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.