Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart
Forum Updated to NodeBB v4.3 + New Features

QChart

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 165 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dan1973
    wrote on last edited by
    #1

    My QChart doesnot show tick values of Y Axis from -500 to 500. see code below:

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QLineSeries *series = new QLineSeries();
        *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26);
        QChart *chart = new QChart();
    //    chart->legend()->hide();
        chart->addSeries(series);
    
        // Customize series
        QPen pen(QRgb(0xfdb157));
        pen.setWidth(5);
        series->setPen(pen);
    
        // Customize chart title
        QFont font;
        font.setPixelSize(18);
        chart->setTitleFont(font);
        chart->setTitleBrush(QBrush(Qt::white));
        chart->setTitle("Customchart example");
    
        // Customize chart background
        QLinearGradient backgroundGradient;
        backgroundGradient.setStart(QPointF(0, 0));
        backgroundGradient.setFinalStop(QPointF(0, 1));
        backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
        backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
        backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
        chart->setBackgroundBrush(backgroundGradient);
    
        // Customize plot area background
        QLinearGradient plotAreaGradient;
        plotAreaGradient.setStart(QPointF(0, 1));
        plotAreaGradient.setFinalStop(QPointF(1, 0));
        plotAreaGradient.setColorAt(0.0, QRgb(0x555555));
        plotAreaGradient.setColorAt(1.0, QRgb(0x55aa55));
        plotAreaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
        chart->setPlotAreaBackgroundBrush(plotAreaGradient);
        chart->setPlotAreaBackgroundVisible(true);
    
        QCategoryAxis *axisX = new QCategoryAxis();
        QCategoryAxis *axisY = new QCategoryAxis();
    
        // Customize axis label font
        QFont labelsFont;
        labelsFont.setPixelSize(12);
        axisX->setLabelsFont(labelsFont);
        axisY->setLabelsFont(labelsFont);
    
        // Customize axis colors
        QPen axisPen(QRgb(0xd18952));
        axisPen.setWidth(2);
        axisX->setLinePen(axisPen);
        axisY->setLinePen(axisPen);
    
        // Customize axis label colors
        QBrush axisBrush(Qt::white);
        axisX->setLabelsBrush(axisBrush);
        axisY->setLabelsBrush(axisBrush);
    
        // Customize grid lines and shades
        axisX->setGridLineVisible(false);
        axisY->setGridLineVisible(false);
        axisY->setShadesPen(Qt::NoPen);
        axisY->setShadesBrush(QBrush(QColor(0x99, 0xcc, 0xcc, 0x55)));
        axisY->setShadesVisible(true);
        axisY->setTickCount(50);
        
        axisX->setRange(0, 30);
        axisY->setRange(0, 600);
    
        chart->setAxisX(axisX, series);
        chart->setAxisY(axisY, series);
        QChartView *chartView = new QChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
        QMainWindow window;
        window.setCentralWidget(chartView);
        window.resize(800, 800);
        window.show();
    
        return a.exec();
    }
    
    SGaistS 1 Reply Last reply
    0
    • D dan1973

      My QChart doesnot show tick values of Y Axis from -500 to 500. see code below:

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QLineSeries *series = new QLineSeries();
          *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26);
          QChart *chart = new QChart();
      //    chart->legend()->hide();
          chart->addSeries(series);
      
          // Customize series
          QPen pen(QRgb(0xfdb157));
          pen.setWidth(5);
          series->setPen(pen);
      
          // Customize chart title
          QFont font;
          font.setPixelSize(18);
          chart->setTitleFont(font);
          chart->setTitleBrush(QBrush(Qt::white));
          chart->setTitle("Customchart example");
      
          // Customize chart background
          QLinearGradient backgroundGradient;
          backgroundGradient.setStart(QPointF(0, 0));
          backgroundGradient.setFinalStop(QPointF(0, 1));
          backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
          backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
          backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
          chart->setBackgroundBrush(backgroundGradient);
      
          // Customize plot area background
          QLinearGradient plotAreaGradient;
          plotAreaGradient.setStart(QPointF(0, 1));
          plotAreaGradient.setFinalStop(QPointF(1, 0));
          plotAreaGradient.setColorAt(0.0, QRgb(0x555555));
          plotAreaGradient.setColorAt(1.0, QRgb(0x55aa55));
          plotAreaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
          chart->setPlotAreaBackgroundBrush(plotAreaGradient);
          chart->setPlotAreaBackgroundVisible(true);
      
          QCategoryAxis *axisX = new QCategoryAxis();
          QCategoryAxis *axisY = new QCategoryAxis();
      
          // Customize axis label font
          QFont labelsFont;
          labelsFont.setPixelSize(12);
          axisX->setLabelsFont(labelsFont);
          axisY->setLabelsFont(labelsFont);
      
          // Customize axis colors
          QPen axisPen(QRgb(0xd18952));
          axisPen.setWidth(2);
          axisX->setLinePen(axisPen);
          axisY->setLinePen(axisPen);
      
          // Customize axis label colors
          QBrush axisBrush(Qt::white);
          axisX->setLabelsBrush(axisBrush);
          axisY->setLabelsBrush(axisBrush);
      
          // Customize grid lines and shades
          axisX->setGridLineVisible(false);
          axisY->setGridLineVisible(false);
          axisY->setShadesPen(Qt::NoPen);
          axisY->setShadesBrush(QBrush(QColor(0x99, 0xcc, 0xcc, 0x55)));
          axisY->setShadesVisible(true);
          axisY->setTickCount(50);
          
          axisX->setRange(0, 30);
          axisY->setRange(0, 600);
      
          chart->setAxisX(axisX, series);
          chart->setAxisY(axisY, series);
          QChartView *chartView = new QChartView(chart);
          chartView->setRenderHint(QPainter::Antialiasing);
          QMainWindow window;
          window.setCentralWidget(chartView);
          window.resize(800, 800);
          window.show();
      
          return a.exec();
      }
      
      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @dan1973 hi,

      Isn't that because you set a range of 0 to 600 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved