java - TeeChart切换图表类型失去Legend

标签 java android teechart

在我正在开发的 Android 应用程序中,我有一个微调器,您可以在其中选择不同数据的不同 View 。目前大多数图表类型都是饼图,这可以正常工作。如果我也从饼图切换到线,那就行了。但是,如果我从折线图切换回饼图,图表显示正常,但图例仅显示“系列 0”。切换回折线图即可显示图例。

它的外观如下:

the problem

这是设置图表基础知识的代码:

    //set up the TeeChart basics
LinearLayout group = (LinearLayout) view.findViewById(R.id.linearLayoutTchart);
chart = new TChart(PainRecordSummary_ViewPager.this);
group.addView(chart);
chart.getPanel().setTransparent(true);

//default 3D to true (will need to reset per chart)
chart.getAspect().setView3D(true);

这是处理切换图表类型的代码:

    switch (graphType) {
case 0: // Location PIE CHART
if(PLS.getLocation() != null){
Pie pieLocation = new Pie(chart.getChart());

chart.removeLegendResolver();
chart.removeAllSeries();
chart.getAspect().setView3D(true);
try {
series = Series.createNewSeries(chart.getChart(), Pie.class,  null);
                } catch (InstantiationException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IllegalAccessException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

for(int i=0; i<PLS.getLocation().size(); i++){
    series.add(PLS.getLocation().get(i).getItemPercent(), PLS.getLocation().get(i).getLocation());
}
pieLocation.add(series);
ColorPalettes.applyPalette(chart.getChart(), Theme.ModernPalette);
chart.getLegend().setAlignment(LegendAlignment.BOTTOM);
chart.getHeader().setVisible(false);
chart.getPanel().setTransparent(true);
chart.getWalls().getBack().setVisible(true);
((com.steema.teechart.styles.Pie)chart.getSeries(0)).setCircled(true);
((com.steema.teechart.styles.Pie)chart.getSeries(0)).getMarks().setVisible(false);
((com.steema.teechart.styles.Pie)chart.getSeries(0)).setExplodeBiggest(12);
((com.steema.teechart.styles.Pie)chart.getSeries(0)).getPen().setVisible(false);
}else{
//show no data
}
break;
case 5: //this will display a TIME SERIES of Pain Locations AVG. SEVERITY
chart.removeAllSeries();
chart.getAspect().setView3D(false);
//X AXIS
//set the x-axis date display to e.g. '01-JAN'
chart.getAxes().getBottom().getLabels().setDateTimeFormat("dd-MMM");
//set the angle of the date display
chart.getAxes().getBottom().getLabels().setAngle(45);
//Y AXIS
//set up the y axis title
AxisTitle yTitle;
yTitle=chart.getAxes().getLeft().getTitle();
yTitle.setCaption("Severity");
//end title
//set y to increment by 1
//override the auto min/max and set to 0/10
chart.getAxes().getLeft().setIncrement(1.00);

for(int i=0; i<PLR.size(); i++){
    Series ln = new Line(chart.getChart());
    ln.setTitle(PLR.get(i).getName());
    SeriesPointer tmpPointer;
    tmpPointer = ((CustomPoint)ln).getPointer();
    tmpPointer.setInflateMargins(true);
    tmpPointer.setStyle(PointerStyle.CIRCLE);
    tmpPointer.setVisible(true);
    for(int j=0; j<PLR.get(i).getItems().size(); j++){
        DateTime dt = new DateTime(
   DateDiff.getYearFromString(PLR.get(i).getItems().get(j).getDateRecord()),
   DateDiff.getMonthFromString(PLR.get(i).getItems().get(j).getDateRecord()),
   DateDiff.getDayFromString(PLR.get(i).getItems().get(j).getDateRecord()));

   ln.add(dt, (double)PLR.get(i).getItems().get(j).getSeverity().intValue());
    }
    ((com.steema.teechart.styles.Line)chart.getSeries(i)).getLinePen().setWidth(2);
}

有人知道为什么传奇没有重新填充吗?我尝试了很多方法来尝试使图例无效或清除它,但没有成功。

非常感谢

最佳答案

在显示 Line 系列时尝试将 LegendStyle 强制为 LegendStyle.SERIES:

tChart1.getLegend().setLegendStyle(LegendStyle.SERIES);

以及在显示 Pie 系列时的 LegendStyle.VALUES:

tChart1.getLegend().setLegendStyle(LegendStyle.VALUES);

刚刚在 Steema 支持论坛中回答了同样的问题 here .

关于java - TeeChart切换图表类型失去Legend,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14130590/

相关文章:

delphi - 鼠标缩放: marquee color

java - 类与接口(interface)上的 FindBugs 和 CheckForNull

java - 如何在同一 fragment Activity 中将数据从 fragment 发送到 fragment ?

android - Cordova Android 不允许向 fb-messenger 打开白名单 Intent

delphi - TeeChart改变轴标题与轴之间的距离DELPHI XE3

javascript - Teechart HTML5,线条颜色和粗细

java - Camel SimpleRegistry 和 DI

java - driver.executeScript() 为简单的 javascript 返回 NullPointerException

java - 如何在 Java 中解析字符串并查找 double

android - 相当于Android中的iOS NSNotificationCenter?