My computer:
Visual Studio 2008, qt 4.7, qwt 6.0
Hi,
I am making a qwt plot from a very large file that has time and prices. The times in the file are all in Unix time as doubles. The plot comes out great with time on the x-axis and prices on the y-axis. The only problem is that the times are all in Unix and not very useful to look at. Does anyone know if there is a way that I can convert the times on the plot into human-readable dates? The kinds of files that I want to plot come from online databases and are all in Unix time.
The only thing I can think of is loading up all the time data from the files and using mktime to make them all into readable dates, but I don't really know how I'd do that. It seems like a lot of work (especially because the files have between 2-4 million time values) Also, I'm not sure if changing these files would make my code break (like the numOfPts when I load the data)...
here is some of my code:
newPlot::newPlot()
{
Curve
->setPen
(QPen(Qt
::red));
Curve->attach(this);
////chose which file to load and load the data
char * FileName = "C:/data/....price_and_time";
FILE * fp = fopen ( FileName, "rb");
if(fp == NULL) EXCEPTION( "no file" );
fseek(fp, 0, SEEK_END);
int numOfPts = ftell( fp )/ (2 * sizeof (double));
double *time = new double[numOfPts];
double *value = new double[numOfPts];
double *tempTime = time;
double *tempValue = value;
fseek(fp, 0, 0);
for( int i=0; i<numOfPts; i++){
int j = fread(tempTime, sizeof(double), 1, fp);
int k = fread(tempValue, sizeof(double), 1, fp);
tempTime++;
tempValue++;
}
Curve->setRawSamples(time, value, numOfPts);
}
if (fp!=NULL)
fclose(fp);
}
newPlot::newPlot()
{
QwtScaleEngine::Floating;
QwtPlotCurve *Curve = new QwtPlotCurve("plotty");
Curve->setPen(QPen(Qt::red));
Curve->setStyle(QwtPlotCurve::Steps);
Curve->attach(this);
////chose which file to load and load the data
char * FileName = "C:/data/....price_and_time";
FILE * fp = fopen ( FileName, "rb");
if(fp == NULL) EXCEPTION( "no file" );
fseek(fp, 0, SEEK_END);
int numOfPts = ftell( fp )/ (2 * sizeof (double));
double *time = new double[numOfPts];
double *value = new double[numOfPts];
double *tempTime = time;
double *tempValue = value;
fseek(fp, 0, 0);
for( int i=0; i<numOfPts; i++){
int j = fread(tempTime, sizeof(double), 1, fp);
int k = fread(tempValue, sizeof(double), 1, fp);
tempTime++;
tempValue++;
}
Curve->setRawSamples(time, value, numOfPts);
}
if (fp!=NULL)
fclose(fp);
}
To copy to clipboard, switch view to plain text mode
I am putting the plot into a gui so that I can add features later:
public:
};
{
setFixedSize(1500,750);
newPlot *myPlot = new newPlot;
layout->addWidget(myPlot);
setLayout(layout);
}
int main(int argc, char * argv[])
{
MyWidget widget;
widget.show();
return app.exec();
}
class MyWidget : public QWidget{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent):QWidget(parent)
{
setFixedSize(1500,750);
newPlot *myPlot = new newPlot;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(myPlot);
setLayout(layout);
}
int main(int argc, char * argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Any ideas?
Thanks for your help!
Bookmarks