Everything compiles with no errors. Basically I copied the Histogram example from the Qwt site and slimmed it down for speed. a few other tweaks were made as well, nothing major though. I read in values from a .txt file where every line is the y value. the x value is the line number. For small text files with small numbers, I am able to clearly see the graph (ie x.interval = 1-10, y.interval = 1-10 respectively, so the text file would just have the 10 numbers in it, separated by a carriage return) but when i try to expand to larger files with 10,000 entries, i get a flat bar across the bottom and the last few entries have infinite y values. when i tried a file with 1 million entries, it crashed (probably having to do with using int). below is the code. any help or suggestions will be happily welcomed!

histogram.cpp
Qt Code:
  1. #include "histogram_item.h"
  2.  
  3. class HistogramItem::PrivateData
  4. {
  5. public:
  6. int attributes;
  7. QColor color;
  8. double reference;
  9. };
  10.  
  11. HistogramItem::HistogramItem(const QwtText &title):
  12. QwtPlotItem(title)
  13. {
  14. init();
  15. }
  16.  
  17. HistogramItem::HistogramItem(const QString &title):
  18. {
  19. init();
  20. }
  21.  
  22. HistogramItem::~HistogramItem()
  23. {
  24. delete d_data;
  25. }
  26.  
  27. void HistogramItem::init()
  28. {
  29. d_data = new PrivateData();
  30.  
  31. setZ(20);
  32. }
  33.  
  34. double HistogramItem::baseline() const
  35. {
  36. return d_data->reference;
  37. }
  38.  
  39. void HistogramItem::setData(const QwtIntervalData &data)
  40. {
  41. d_data->data = data;
  42. itemChanged();
  43. }
  44.  
  45. void HistogramItem::setColor(const QColor &color)
  46. {
  47. if ( d_data->color != color )
  48. {
  49. d_data->color = color;
  50. itemChanged();
  51. }
  52. }
  53.  
  54. QwtDoubleRect HistogramItem::boundingRect() const
  55. {
  56. QwtDoubleRect rect = d_data->data.boundingRect();
  57. return rect;
  58. }
  59.  
  60.  
  61. int HistogramItem::rtti() const
  62. {
  63. return QwtPlotItem::Rtti_PlotHistogram;
  64. }
  65.  
  66. void HistogramItem::draw(QPainter *painter, const QwtScaleMap &xMap,
  67. const QwtScaleMap &yMap, const QRect &) const
  68. {
  69. const QwtIntervalData &iData = d_data->data;
  70.  
  71. painter->setPen(QPen(d_data->color));
  72. // const int x0 = xMap.transform(baseline());
  73. const int y0 = yMap.transform(baseline());
  74.  
  75. for ( int i = 0; i < (int)iData.size(); i++ )
  76. {
  77. const int y2 = yMap.transform(iData.value(i));
  78. int x1 = xMap.transform(iData.interval(i).minValue());
  79. int x2 = xMap.transform(iData.interval(i).maxValue());
  80. drawBar(painter, Qt::Vertical,
  81. QRect(x1, y0, x2 - x1, y2 - y0) );
  82. }
  83. }
  84.  
  85. void HistogramItem::drawBar(QPainter *painter,
  86. Qt::Orientation, const QRect& rect) const
  87. {
  88. painter->save();
  89.  
  90. const QColor color(painter->pen().color());
  91. #if QT_VERSION >= 0x040000
  92. const QRect r = rect.normalized();
  93. #else
  94. const QRect r = rect.normalize();
  95. #endif
  96.  
  97. const int factor = 125;
  98. const QColor light(color.light(factor));
  99. const QColor dark(color.dark(factor));
  100.  
  101. painter->setBrush(color);
  102. QwtPainter::drawRect(painter, r.x()+1 , r.y()+1,
  103. r.width()-3, r.height()-3);
  104.  
  105. painter->restore();
  106. }
To copy to clipboard, switch view to plain text mode 

histogram.h
Qt Code:
  1. #ifndef HISTOGRAM_ITEM_H
  2. #define HISTOGRAM_ITEM_H
  3. #include <qglobal.h>
  4. #include <qcolor.h>
  5. #include <qapplication.h>
  6. #include <qmainwindow.h>
  7. #include <qwt_counter.h>
  8. #include <qtoolbar.h>
  9. #include <qlabel.h>
  10. #include <qlayout.h>
  11. #include <qfile.h>
  12. #include <stdio.h>
  13. #include <iostream>
  14. #include <fstream>
  15. #include <QMessageBox>
  16. #include <QMainWindow>
  17. #include <QTextStream>
  18. #include <QTextOStream>
  19. #include <stdlib.h>
  20. #include <qpen.h>
  21. #include <qwt_plot.h>
  22. #include <qwt_plot_grid.h>
  23. #include <qwt_plot_marker.h>
  24. #include <qwt_interval_data.h>
  25. #include <qstring.h>
  26. #include <qpainter.h>
  27. #include <qwt_painter.h>
  28. #include <qwt_scale_map.h>
  29. #include "qwt_plot_item.h"
  30.  
  31. class QString;
  32.  
  33. class HistogramItem: public QwtPlotItem
  34. {
  35. public:
  36. explicit HistogramItem(const QString &title = QString::null);
  37. explicit HistogramItem(const QwtText &title);
  38. virtual ~HistogramItem();
  39.  
  40. void setData(const QwtIntervalData &data);
  41. const QwtIntervalData &data() const;
  42.  
  43. void setColor(const QColor &);
  44. QColor color() const;
  45.  
  46. virtual QwtDoubleRect boundingRect() const;
  47.  
  48. virtual int rtti() const;
  49.  
  50. virtual void draw(QPainter *, const QwtScaleMap &xMap,
  51. const QwtScaleMap &yMap, const QRect &) const;
  52.  
  53. void setBaseline(double reference);
  54. double baseline() const;
  55.  
  56. enum HistogramAttribute
  57. {
  58. Auto = 0,
  59. Xfy = 1
  60. };
  61.  
  62. void setHistogramAttribute(HistogramAttribute, bool on = true);
  63. bool testHistogramAttribute(HistogramAttribute) const;
  64.  
  65. protected:
  66. virtual void drawBar(QPainter *,
  67. Qt::Orientation o, const QRect &) const;
  68.  
  69. private:
  70. void init();
  71.  
  72. class PrivateData;
  73. PrivateData *d_data;
  74. };
  75.  
  76. #endif
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include "histogram_item.h"
  2.  
  3.  
  4. int main(int argc, char **argv)
  5. {
  6. QApplication a(argc, argv);
  7.  
  8. QwtPlot plot;
  9. plot.setCanvasBackground(QColor(Qt::white));
  10. plot.setTitle("Histogram");
  11.  
  12. QwtPlotGrid *grid = new QwtPlotGrid;
  13. grid->enableXMin(true);
  14. grid->enableYMin(true);
  15. grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
  16. grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
  17. grid->attach(&plot);
  18.  
  19. HistogramItem *histogram = new HistogramItem();
  20. histogram->setColor(Qt::darkCyan);
  21.  
  22. const int numValues = 10000;
  23.  
  24. QwtArray<QwtDoubleInterval> intervals(numValues);
  25. QwtArray<double> values(numValues);
  26.  
  27. QStringList lines;
  28. QFile file( "C:\\path\\to\\file\\file.txt" );
  29. int count[10000];
  30. if(file.open(QFile::ReadOnly))
  31. {
  32. QTextStream stream(&file);
  33. QString line;
  34. int i = 1;
  35. line = stream.readLine();
  36.  
  37. while(!line.isNull())
  38. {
  39. line = stream.readLine();
  40. if(line.toInt() != 0)
  41. {
  42. lines += line;
  43. count[i-1] = line.toInt();
  44. i++;
  45. }
  46. else{
  47. lines+=line;
  48. i++;
  49. }
  50.  
  51. }
  52. }
  53. file.close();
  54.  
  55. double pos = 0.0;
  56. for ( int i = 0; i < (int)intervals.size(); i++ )
  57. {
  58. int width = 1;
  59. int value = count[i];
  60. intervals[i] = QwtDoubleInterval(pos-.5*double(width), pos + .5*double(width));
  61. values[i] = value;
  62.  
  63. pos += width;
  64. }
  65.  
  66. histogram->setData(QwtIntervalData(intervals, values));
  67. histogram->attach(&plot);
  68.  
  69. plot.setAxisScale(QwtPlot::yLeft, 0.0, 10000.0);
  70. plot.setAxisScale(QwtPlot::xBottom, -1, pos);
  71. plot.replot();
  72.  
  73. #if QT_VERSION < 0x040000
  74. a.setMainWidget(&plot);
  75. #endif
  76.  
  77. plot.resize(800,600);
  78. plot.show();
  79.  
  80. return a.exec();
  81. }
To copy to clipboard, switch view to plain text mode