Search code examples
javateechart

change single point color in teechart


i'm using teechart in java.I want to change some points color in a series,not all of the points.If the point's value is over a specific value,then turn the point into red.
i just know how to change all the point's color,and here is my code.

xline.getPointer().setVisible(true); // 数据点突出显示
// xline.getPointer().setStyle(PointerStyle.CIRCLE);
xline.getPointer().setHorizSize(2);
xline.getPointer().setVertSize(2);
xline.getPointer().setColor(Color.black);
xline.getPointer().getPen().setColor(Color.black);

can someone show me some code on how to do this?


Solution

  • You can set a color per each point. Ie:

        tChart1.getAspect().setView3D(false);
        Line xline = new Line(tChart1.getChart());
        xline.fillSampleValues();
    
        xline.getPointer().setVisible(true); // 数据点突出显示
        // xline.getPointer().setStyle(PointerStyle.CIRCLE);
        xline.getPointer().setHorizSize(2);
        xline.getPointer().setVertSize(2);
        //xline.getPointer().setColor(Color.black);
        //xline.getPointer().getPen().setColor(Color.black);
    
        double thr = xline.getYValues().getMinimum() + (xline.getYValues().getMaximum() - xline.getYValues().getMinimum()) / 3;
        for (int i=0; i<xline.getCount(); i++) {
            if (xline.getYValues().getValue(i) > thr) {
                xline.getColors().setColor(i, Color.black);
            }
        }