|
The porblem of using makechart functions in XYChart. |
Posted by EunMi Lee on Apr-28-2014 09:50 |
|
Hi
I draw multiaxes chart.
I will draw multiaxes, After I make chart that is same number of labels and interval of
labels prev chart.
Sample)
// Create a XYChart object of size 600 x 360 pixels. Use a vertical gradient
// color from sky blue (aaccff) to white (ffffff) as background. Set border to
// grey (888888). Use rounded corners. Enable soft drop shadow.
XYChart *c = new XYChart(600, 360);
c->setBackground(c->linearGradientColor(0, 0, 0, c->getHeight(), 0xaaccff,
0xffffff), 0x888888);
c->setRoundedFrame();
c->setDropShadow();
// Add a title box to the chart using 15 pts Arial Bold Italic font. Set top
// margin to 16 pixels.
TextBox *title = c->addTitle("Multiple Axes Demonstration", "arialbi.ttf", 15);
title->setMargin(0, 0, 16, 0);
// Set the plotarea at (100, 80) and of size 400 x 230 pixels, with white
// (ffffff) background. Use grey #(aaaaa) dotted lines for both horizontal and
// vertical grid lines.
c->setPlotArea(100, 80, 400, 230, 0xffffff, -1, -1, c->dashLineColor(0xaaaaaa,
Chart::DotLine), -1);
// Add a legend box with the bottom center anchored at (300, 80) (top center of
// the plot area). Use horizontal layout, and 8 points Arial Bold font. Set
// background and border to transparent.
LegendBox *legendBox = c->addLegend(300, 80, false, "arialbd.ttf", 8);
legendBox->setAlignment(Chart::BottomCenter);
legendBox->setBackground(Chart::Transparent, Chart::Transparent);
// Set the labels on the x axis.
c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]
))));
// Display 1 out of 3 labels on the x-axis.
c->xAxis()->setLabelStep(3);
// Add a title to the x-axis
c->xAxis()->setTitle("Hour of Day");
// Add a title on top of the primary (left) y axis.
c->yAxis()->setTitle("Power\\n(Watt)")->setAlignment(Chart::TopLeft2);
// Set the axis, label and title colors for the primary y axis to red (c00000) to
// match the first data set
c->yAxis()->setColors(0xcc0000, 0xcc0000, 0xcc0000);
// Add a title on top of the secondary (right) y axis.
c->yAxis2()->setTitle("Load\\n(Mbps)")->setAlignment(Chart::TopRight2);
// Set the axis, label and title colors for the secondary y axis to green
// (00800000) to match the second data set
c->yAxis2()->setColors(0x008000, 0x008000, 0x008000);
// Add the third y-axis at 50 pixels to the left of the plot area
Axis *leftAxis = c->addAxis(Chart::Left, 50);
// Add a title on top of the third y axis.
leftAxis->setTitle("Temp\\n(C)")->setAlignment(Chart::TopLeft2);
// Set the axis, label and title colors for the third y axis to blue (0000cc) to
// match the third data set
leftAxis->setColors(0x0000cc, 0x0000cc, 0x0000cc);
// Add the fouth y-axis at 50 pixels to the right of the plot area
Axis *rightAxis = c->addAxis(Chart::Right, 50);
// Add a title on top of the fourth y axis.
rightAxis->setTitle("Error\\n(%)")->setAlignment(Chart::TopRight2);
// Set the axis, label and title colors for the fourth y axis to purple (880088)
// to match the fourth data set
rightAxis->setColors(0x880088, 0x880088, 0x880088);
// Add a line layer to for the first data set using red (c00000) color, with a
// line width of 2 pixels
LineLayer *layer0 = c->addLineLayer(DoubleArray(data0, (int)(sizeof(data0) /
sizeof(data0[0]))), 0xcc0000, "Power");
layer0->setLineWidth(2);
// Add a line layer to for the second data set using green (00c0000) color, with
// a line width of 2 pixels. Bind the layer to the secondary y-axis.
LineLayer *layer1 = c->addLineLayer(DoubleArray(data1, (int)(sizeof(data1) /
sizeof(data1[0]))), 0x008000, "Load");
layer1->setLineWidth(2);
layer1->setUseYAxis2();
// Add a line layer to for the third data set using blue (0000cc) color, with a
// line width of 2 pixels. Bind the layer to the third y-axis.
LineLayer *layer2 = c->addLineLayer(DoubleArray(data2, (int)(sizeof(data2) /
sizeof(data2[0]))), 0x0000cc, "Temperature");
layer2->setLineWidth(2);
layer2->setUseYAxis(leftAxis);
// Add a line layer to for the fourth data set using purple (880088) color, with
// a line width of 2 pixels. Bind the layer to the fourth y-axis.
LineLayer *layer3 = c->addLineLayer(DoubleArray(data3, (int)(sizeof(data3) /
sizeof(data3[0]))), 0x880088, "Error Rate");
layer3->setLineWidth(2);
layer3->setUseYAxis(rightAxis);
// Output the chart
c->makeChart("multiaxes.png");
I want that new XYChart is same max value of labels, min value of labels and interval of
labels.
c = new XYChart(2400, 1440);
// Set the plotarea at (100, 80) and of size 400 x 230 pixels, with white
// (ffffff) background. Use grey #(aaaaa) dotted lines for both horizontal and
// vertical grid lines.
c->setPlotArea(400, 320, 1600, 920, 0xffffff, -1, -1, c->dashLineColor(0xaaaaaa,
Chart::DotLine), -1);
??..
// Add the third y-axis at 50 pixels to the left of the plot area
Axis *leftAxis = c->addAxis(Chart::Left, 50);
// Add a title on top of the third y axis.
leftAxis->setTitle("Temp\\n(C)")->setAlignment(Chart::TopLeft2);
// Set the axis, label and title colors for the third y axis to blue (0000cc) to
// match the third data set
leftAxis->setColors(0x0000cc, 0x0000cc, 0x0000cc);
// Add the fouth y-axis at 50 pixels to the right of the plot area
Axis *rightAxis = c->addAxis(Chart::Right, 50);
// Add a title on top of the fourth y axis.
rightAxis->setTitle("Error\\n(%)")->setAlignment(Chart::TopRight2);
// Set the axis, label and title colors for the fourth y axis to purple (880088)
// to match the fourth data set
rightAxis->setColors(0x880088, 0x880088, 0x880088);
????
// Output the chart
c->makeChart("multiaxes1.png");
Does it possible?
I would be grateful if you could send me sample code.
I look forward to your reply to our inquiry.
Thank you. |
Re: The porblem of using makechart functions in XYChart. |
Posted by Peter Kwan on Apr-29-2014 03:37 |
|
Hi EunMi Lee,
First, you would need to store the axis min, max and increment values for your "previous
chart". For example:
//After markChart, stores the axis configuration for future use
double yAxisMin = c->yAxis()->getMinValue();
double yAxisMax = c->yAxis()->getMaxValue();
DoubleArray yAxisTicks = c->yAxis()->getTicks();
double yAxisInc = yAxisTicks[1] - yAxisTicks[0];
double leftAxisMin = leftAxis->getMinValue();
double leftAxisMax = leftAxis->getMaxValue();
DoubleArray leftAxisTicks = leftAxis->getTicks();
double leftAxisInc = leftAxisTicks[0] - leftAxisTicks[0];
.....
In future, if you want to create another chart with the same axis scale and labels, you
can use:
c->yAxis()->LinearScale(yAxisMin, yAxisMax, yAxisInc);
leftAxisInc->LinearScale(leftAxisMin, leftAxisMax, leftAxisInc);
.....
Hope this can help.
Regards
Peter Kwan |
|