|
Vertical option on DataLabel. |
Posted by Yejin Lee on Aug-11-2017 18:13 |
|
I set [DataLabel] with the option "Vertical", and i got the problem.
If the format is {value}, {percent}%, {dataSetName} with vertical option, Label comes upside down.(written down from the bottom side.)
To fix this issue, first of all, I modified {dataSetName} with the code you gave me last time.(ToVertical, ToVerticalArray)
As the result, DataLabel is changed as i wish, but it made legend characters shown vertically too.
Also, I found the issue won't be fixed from your last solution if i use format as {value} or {percent}.
My code is
...
xyChart.addLineLayer(data.GetDoubleArray(), nColor, ToVertical(pName = TCHARtoUTF8(pLayer->m_name.data())));
Is there any solution to write all types of DataLabel's format from the top when i set vertical option? (without vertical legend.)
How can i modify my code?
|
Re: Vertical option on DataLabel. |
Posted by Peter Kwan on Aug-12-2017 12:22 |
|
Hi Yejin,
Sorry for the late reply. I have attached a chart image that may meet your requirement. The code I use are:
// The data set names
const char *dataSetNames[] = { Name1, Name2 };
....
// Add the data set using the original names (no need to use ToVertical)
layer->addDataSet(data0, 0xaaccee, dataSetNames[0]);
layer->addDataSet(data1, 0xbbdd88, dataSetNames[1]);
// Add the vertical names as an extra field
layer->addExtraField(ToVerticalArray(StringArray(dataSetNames, 2)));
// The data label uses the vertical name ({dsField0}, followed by a rotated {value}
layer->setDataLabelFormat("<*block*>{dsField0}<*/*>n<*block,angle=270*>: {value}<*/*>");
// Use a font that can display Japanese
layer->setDataLabelStyle("mingliu.ttc", 10);
Hope this can help.
Regards
Peter Kwan
|
Re: Vertical option on DataLabel. |
Posted by Yejin Lee on Aug-16-2017 10:05 |
|
Thanks for the reply.
I didn't mean that i want to rotate value numbers when I use {value} as DataLabel format.
For example, if i set the value 100.23
hope it's shown like
1
0
0
.
2
3
is there any solutions? |
Re: Vertical option on DataLabel. |
Posted by Peter Kwan on Aug-16-2017 20:59 |
|
Hi Yejin,
May be you can try the following method, which uses Layer.addCustomDataLabel to add custom labels. We need a ToVerticalAll below, which will make any text vertical. (The ToVertical in my other message to you will make CJK characters vertical, but will rotate alphanumeric and "half-width" characters.)
// Converts a text string to vertical by inserting newlines
class ToVerticalAll
{
public:
ToVertical(const char *str) {
while (*str) {
ret += *str;
if (*++str) ret += '\\n';
}
}
operator const char *() {
return ret.c_str();
}
private:
std::string ret;
};
// Add vertical data labels
for (int i = 0; i < layer->getDataSetCount(); ++i)
for (int j = 0; j < dataPointCount; ++j)
layer->addCustomDataLabel(i, j, ToVerticalAll(c->formatValue(data[j], "{value}")), "arial.ttf", 10, 0x000000);
Hope this can help.
Regards
Peter Kwan |
Re: Vertical option on DataLabel. |
Posted by Yejin Lee on Aug-19-2017 01:40 |
|
I have one more question,
I'm using two kinds of function you gave me last time. following:
layer->addExtraField
layer->addCustomDataLabel
I think I can make layers with it.
If i set the labels with function setDataLabelFormat("{dsField0}"), i think it only works with one layer, not work with second, third layer.
what is {dsField0}, {dsField1}... means,
and What should I do to show label when i use "addExtraField" and "addCustomDataLabel" each? |
Re: Vertical option on DataLabel. |
Posted by Peter Kwan on Aug-20-2017 21:40 |
|
Hi Yejin,
For the:
layer->addExtraField
layer->addCustomDataLabel
it should work with multiple layers. For example:
BarLayer layer1 = c->addBarLayer2(.....);
layer1->addDataSet(....);
layer1->addDataSet(....);
layer1->addExtraField(....);
layer1->addCustomDataLabel(....);
layer1->setDataLabelFormat("{dsField0}"),
BarLayer layer2 = c->addBarLayer2(.....);
layer2->addDataSet(....);
layer2->addDataSet(....);
layer2->addExtraField(....);
layer2->addCustomDataLabel(....);
layer2->setDataLabelFormat("{dsField0}"),
The "Field0" refers to the first extra field in a layer. In the above code, each layer only has one extra field, so it is always "Field0". If you call addExtraField multiple times for the same layer to add multiple string arrays, then you can use "Field0", "Field1", ... to refer to the multiple extra fields.
The "ds" means the extra field is indexed by the data set. For example, suppose you have 2 data set in a bar layer, and each data set has 5 bars. In this case the {dsField0} means the first data set is associated with the first element in the extra field array, and the second data set is associated with the second element in the extra field array.
If you use {field0}, it means the extra field is indexed by the array index. In this case, the first bar in a data set is associated with the first element of the extra field array, and the second bar in a data set is associated with the second element of the extra field array, and the third bar in a data set is associated with the third element of the extra field array, and so on.
If you think it is not working as expected, is it possible to provide a simple example so I may understand how you are using the extra field?
Regards
Peter Kwan |
Re: Vertical option on DataLabel. |
Posted by Yejin Lee on Aug-19-2017 00:31 |
|
Do you think setting data label format as {percent}% and make it vertical is possible?
I'm trying, but i cannot find how to get the percentage, first..
I'm trying to modify my code with your solutions so far, but there are pretty big amount of codes to make it work.
I have to add many lines. it defeats stability of the program i think.
Do you have any expectation to make "vertical function" works? (hope words will be written down from the top) |
Re: Vertical option on DataLabel. |
Posted by Peter Kwan on Aug-20-2017 21:25 |
|
Hi Yejin,
There are many definition of "percentage" in your chart. I am not sure what type of percentage you are using.
In ChartDirector. "{percent}" refers to the percentage of a bar segment relative to the whole bar. This is useful in a stacked bar that has multiple bar segments for each bar. For a non-stacked bar, the "{percent}" is always 100%, as the bar segment is 100% of the bar.
For the bar chart example I used on my previous post in Aug 12, there are 5 groups of bars. Each group has 2 bars. So the chart has 10 bars. The percentage can refer to the percentage of a bar inside a bar group. It can refer to a bar relative to the 5 bars of the same data set. It can also refer to a bar relative to all the 10 bars in the same layer.
For your case, I think the best method is to compute the percentage you want with your own code. For example, if you are referring to the percentage related to the bars in the same data set, you can use:
double sum = new ArrayMath(data).sum();
for (int i = 0; i < layer->getDataSetCount(); ++i)
for (int j = 0; j < dataPointCount; ++j)
layer->addCustomDataLabel(i, j, ToVerticalAll(c->formatValue(data[j] / sum * 100, "{value|2}%")), "arial.ttf", 10, 0x000000);
Hope this can help.
Regards
Peter Kwan |
|