在MFC TeeChart中绘制一个饼图

时间:2017-05-18 12:48:28

标签: c++ mfc teechart

我的英语不是很好,所以请原谅我。我已经在饼图中成功添加了我的数据,但饼图并没有显示控件中显示的数据。

控件的属性似乎已经正确配置。我不知道问题出在哪里,因为我已经度过了整个晚上。

BOOL CStatInfPieDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    char temp1[100];
    char temp2[100];
    CString str;
    // TODO:  Add extra initialization here
    CSeries series = (CSeries)statInfPie.Series(0);
    int size = stationInfList.size();
    series.put_ColorEachPoint(true);
    srand(time(NULL));
    for (int i = 0; i < size; i++) {
        sprintf(temp1, "%s/%d  ", iptostr(stationInfList[i].netaddrA), toCidr(stationInfList[i].netmaskA));
        sprintf(temp2, "%s/%d", iptostr(stationInfList[i].netaddrB), toCidr(stationInfList[i].netmaskB));
        strcat(temp1, temp2);
        str = CString(temp1);
        series.Add(stationInfList[i].bcountAToB + stationInfList[i].bcountBToA, str, RGB(rand() % 255, rand() % 255, rand() % 255));
        memcpy(temp1, "\0", sizeof(temp1));
        memcpy(temp2, "\0", sizeof(temp2));
    }
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

上面的代码示例初始化包含TeeChart控件的对话框。我通过函数Add()添加数据。数组temp1和数组temp2是我的描述inf。在编译并运行我的程序之后,结果显示在图片中。

enter image description here

1 个答案:

答案 0 :(得分:1)

TeeChart尝试为长标签和Legend设置空间,自动减小Pie的直径。在这种情况下,结果是极端的;馅饼没有半径。

可以通过以下几种方式之一解决: 最新版本的TeeChart(AX)包含一个名为InsideSlice for PieMarks的属性。 即,TChart1.Series(0).asPie.PieMarks.InsideSlice = True

对于旧版本的TeeChart,此属性不可用,您可以手动将Arrowlength(连接到Mark)设置为负值: 即。 TChart1.Series(0).Marks.ArrowLength = -20

系列标记可以设置为渲染多线,占用较少的宽度: 即。 TChart1.Series(0).Marks.MultiLine = True

如果图表中的图例包含很长的标签,那么图表的可读性也会受到影响。 Legend可以设置为Visible false或者告诉不要调整Chart Series(Pie)的大小。 即。 TChart1.Legend.ResizeChart = False

或者可以位于Pie下面 即。 TChart1.Legend.Alignment = laBottom

这里需要设计思想。显示长点值标签(系列标记)并重复传奇中的一些信息占据了可以显示图表的大量工作空间。如果将图例放在图表下方,并且面板的大小相应,并且可能使用的信息不会复制系列标记&#39;信息(使用不同的图例文字样式)加上设置多行的系列标记,箭头长度较短,那么整体结果应该是非常易读的。