[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppVclTChart
Can be forward declarated with:
In the implementation file, #include chart.hpp:
The TChart Component cannot plot a surface plot. You can use Bilderbikkel's SurfacePlotter class for this.
Note that the CLX library does NOT contain an equivalent of this Component.
How-to's overview:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppVclTChart
(C++ VCL) TChart
Visual Component for visualizing data series.Can be forward declarated with:
namespace Chart { class TChart; };
In the implementation file, #include chart.hpp:
- include <Chart.hpp>
The TChart Component cannot plot a surface plot. You can use Bilderbikkel's SurfacePlotter class for this.
Note that the CLX library does NOT contain an equivalent of this Component.
How-to's overview:
- How to: read the values from a TChart?
- How to: calculate a best-fitting line of the values in a TChart?
- How to: draw a best fitting line of a ChartSeries?
How to: read the values from a TChart?
//Fill the Chart with values for (double x = 0.0; x < 10.0; x+=0.1234) { const double y = x * x; Chart1->Series[0]->AddXY(x,y); } //Copy the pointers to the values TChartValueList * xValues(Chart1->Series[0]->XValues); TChartValueList * yValues(Chart1->Series[0]->YValues); //Assume there are as many X's as Y's assert(xValues->Count()==yValues->Count()); //Loop through them and put them in a TRichEdit const int count = xValues->Count(); for (int i=0; i!=count; ++i) { String myString = FloatToStr(xValues->operator [](i)) + " " + FloatToStr(yValues->operator [](i)); RichEdit1->Lines->Add(myString); }
- include <assert>
How to: calculate a best-fitting line of the values in a TChart ?
void getTrendLine(const TChartSeries * series, double& offset, double& slope)
{
const int nValues = (const_cast<TChartSeries*>(series))->Count(); //VCL is not const-correct
//Calculate meanX and meanY
double sumX = 0.0;
double sumY = 0.0;
for (int i=0; i!=nValues; ++i)
{
sumX += series->XValues->operator [](i);
sumY += series->YValues->operator [](i);
}
const double meanX = sumX / static_cast<double>(nValues);
const double meanY = sumY / static_cast<double>(nValues);
double sumBup = 0.0;
double sumBdown = 0.0;
for (int i=0; i<nValues; ++i)
{
sumBup += ((series->XValues->operator [](i) - meanX)
* (series->YValues->operator [](i) - meanY));
sumBdown+= ((series->XValues->operator [](i) - meanX)
* (series->XValues->operator [](i) - meanX));
}
slope = sumBup/sumBdown;
offset = meanY - (slope*meanX);
}
How to: draw a best fitting line of a ChartSeries?
Using the function getTrendLine above:
void drawTrendLine(TChart * chart,const int& seriesFrom,const int& seriesTo)
{
double offset, slope;
const double minX = chart->Series[seriesFrom]->XValues->MinValue;
const double maxX = chart->Series[seriesFrom]->XValues->MaxValue;
if (minX!=maxX)
{
getTrendLine(chart->Series[seriesFrom],offset,slope);
chart->Series[seriesTo]->AddXY(minX, offset + (minX * slope));
chart->Series[seriesTo]->AddXY(maxX, offset + (maxX * slope));
}
}
Code links
TChart links
TChart is not present in the CLX- Pascal VCL TChart
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
