Coder Social home page Coder Social logo

Charts do not work properly about qxlsx HOT 9 CLOSED

qtexcel avatar qtexcel commented on May 13, 2024
Charts do not work properly

from qxlsx.

Comments (9)

j2doll avatar j2doll commented on May 13, 2024

Dear edosad.
Could you show me the script you wrote?
I do not know the exact meaning you said.

from qxlsx.

edosad avatar edosad commented on May 13, 2024

from qxlsx.

j2doll avatar j2doll commented on May 13, 2024

Dear edosad.

2️⃣ You can check the existence of the file as follows.
See https://forum.qt.io/post/352670.

// [static] bool QFile::exists(const QString &fileName)
qDebug() << QFile::exists("/home/pw/docs/file.txt");

from qxlsx.

j2doll avatar j2doll commented on May 13, 2024

From @edosad

Dear Jay Two,

Thanks for looking into this.
I'm afraid I failed to explain the problem properly. So I create a chart, then I open it in the xslx file and format the chart - add axes title,chart title,legend etc. Then I use the script to add more charts to the very same xslx file. And then I found that all of the changes I made (axes titles,legend etc) are gone because of the addition of the new data to the same file. My question is how it can be overcome? In other words how I can keep all of the changes while adding new sheets using the script to the same file?

void sat_calc::generate_report(){

    double d1, d2, d3;

    QFile input(chromatogram);

    if(!report_file.contains(".xlsx",Qt::CaseInsensitive))
        report_file+=".xlsx";

    if (!input.open(QIODevice::ReadOnly)){
        std::cout<<"\nNo such file or directory: "<<chromatogram.toStdString()<<"!\n\n";
        //system("pause");
        //exit(1);

    }
    else{

        QXlsx::Document output(report_file);

        output.addSheet(sheet_name);
        output.selectSheet(sheet_name);
        QString chrom_data_array="A"+QString::number(output_line_count+3);


        unsigned int input_line_count=0;

        int step=1;

        QString string_buffer, trash;
        QTextStream stream_buffer(&input);

        QXlsx::Format row_data, simple_green, title_stile;
        row_data.setBorderStyle(QXlsx::Format::BorderThin);
        row_data.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
        row_data.setNumberFormat("0.000");
        simple_green.setFontColor(QColor(Qt::green));
        simple_green.setBorderStyle(QXlsx::Format::BorderThin);
        title_stile.setFontBold(true);
        title_stile.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
        title_stile.setVerticalAlignment(QXlsx::Format::AlignVCenter);
        title_stile.setPatternBackgroundColor(QColor(225,225,225));
        title_stile.setBorderStyle(QXlsx::Format::BorderMedium);
        output.write(output_line_count+2,1,"volume, ml",title_stile);
        output.write(output_line_count+2,2,"OD, mAu",title_stile);

            while (!stream_buffer.atEnd()) {
                if(input_line_count%step==0){
                    for(int j=0; j<2; j++){
                        if(input_line_count>2){
                            if(input_line_count==2&&j==0){
                                stream_buffer>>string_buffer;

                            }
                            if(input_line_count==3&&j==0){
                                stream_buffer>>d1;
                                output.write(output_line_count,j+1,d1,simple_green);
                            }
                            if(input_line_count==4&&j==0){
                                stream_buffer>>d2;
                                step=(int)(precision/(d2-d1));
                                std:: cout<<"\nstep  "<<step<<endl;
                                output.write(output_line_count,j+1,d2,simple_green);
                            }
                            if(j||input_line_count>4){
                                stream_buffer>>d3;
                                output.write(output_line_count,j+1,d3,row_data);
                            }
                        }

                }
                output_line_count++;
            }
            trash=stream_buffer.readLine();
            input_line_count++;
            }

            chrom_data_array+=":B"+QString::number(output_line_count-1);
            Chart * Crom = output.insertChart(3, 5, QSize(600, 500));
            Crom->setChartType(Chart::CT_Scatter);
            Crom->addSeries(CellRange(chrom_data_array));

            output.saveAs(report_file);
            input.close();
    }

       std:: cout<<"end"<<std::endl;
}

from qxlsx.

j2doll avatar j2doll commented on May 13, 2024

Dear @edosad

  • I have implemented some function that you want. v1.3.14

    • saving axis title of line/bar/scatter chart.
    • loading function is not supported, yet.
  • See chartsquestions example that is based on your example.

// sat_calc.cpp
// ...
    Chart * Crom = output.insertChart( 3, 5, QSize(600, 500) );
    Crom->setChartType( Chart::CT_Scatter );
    Crom->addSeries( CellRange(chrom_data_array) );
    Crom->setAxisTitle( Chart::ChartAxisPos::Left, QString("left title") ); // dev22
    Crom->setAxisTitle( Chart::ChartAxisPos::Bottom, QString("bottom title") ); // dev22
// ...

Try the test.

2018-12-20-18_34_37

from qxlsx.

j2doll avatar j2doll commented on May 13, 2024
  • The function to set the title of the chart has been added. v.1.3.16
 Chart * Crom = output.insertChart( 3, 5, QSize(600, 500) );
 Crom->setChartType( Chart::CT_Scatter );
 Crom->addSeries( CellRange(chrom_data_array) );
 Crom->setAxisTitle( Chart::Left, QString("left title") ); 
 Crom->setAxisTitle( Chart::Bottom, QString("bottom title") );
 Crom->setChartTitle( QString("hello chart") ); 

from qxlsx.

edosad avatar edosad commented on May 13, 2024

from qxlsx.

j2doll avatar j2doll commented on May 13, 2024

Dear @edosad

Thank you for reporting issue.

It looks like I will need to re-check the chart's architecture of previous project.

❕ Notice: The URL of the project has changed. https://github.com/QtExcel/QXlsx

from qxlsx.

j2doll avatar j2doll commented on May 13, 2024

Dear Jay Two, Thank you very much for your help and reply and apologies for the late answer. We have tested the new features,it's great,thanks a lot for adding them! However, the problem I was referring to earlier still remains: addition of a new chart into the file with the chart that has been already modified cancels all of the previous changes. Just try to add one chart,modify it and then add another one,you will see. It would be very helpful if you could also look into it, when you'd have time of course. Also just a thought,would it be possible to add other tools for chart design? Such as selection of chart type,curves colour etc. Thank you again very much,it's a great tool that helped us in many ways. Kind wishes,

On 27 Dec 2018, at 06:10, Jay Two @.***> wrote: The function to set the title of the chart has been added. v.1.3.16 Chart * Crom = output.insertChart( 3, 5, QSize(600, 500) ); Crom->setChartType( Chart::CT_Scatter ); Crom->addSeries( CellRange(chrom_data_array) ); Crom->setAxisTitle( Chart::Left, QString("left title") ); Crom->setAxisTitle( Chart::Bottom, QString("bottom title") ); Crom->setChartTitle( QString("hello chart") ); — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Dear @edosad
Can I see the test code for the case you mentioned?
Is this the following code type?

int test( QVector<QVariant> params )
{
    qDebug() << " current path : " << QDir::currentPath();

    using namespace QXlsx;

    Document output;

    QString strSheet = "c-sheet1";
    output.addSheet(strSheet);
    output.selectSheet(strSheet);

    output.write( 1, 1, QVariant(11) );
    output.write( 1, 2, QVariant(12) );
    output.write( 1, 3, QVariant(13) );
    output.write( 2, 1, QVariant(21) );
    output.write( 2, 2, QVariant(22) );
    output.write( 2, 3, QVariant(23) );

    // [1] create chart 1
    Chart* ptrChart = output.insertChart( 3, 5, QSize(600, 500) );
    ptrChart->setChartType( Chart::CT_ScatterChart );
    ptrChart->addSeries( CellRange("A3:B3") );
    ptrChart->setAxisTitle( Chart::Left, QString("left title") );
    ptrChart->setAxisTitle( Chart::Bottom, QString("bottom title") );
    ptrChart->setChartTitle( QString("hello chart") );

    // [2] create chart 2
    Chart* ptrChart2 = output.insertChart( 3, 15, QSize(600, 500) );
    ptrChart2->setChartType( Chart::CT_ScatterChart );
    ptrChart2->addSeries( CellRange("A1:B3") );
    ptrChart2->setAxisTitle( Chart::Left, QString("left title") );
    ptrChart2->setAxisTitle( Chart::Bottom, QString("bottom title") );
    ptrChart2->setChartTitle( QString("hello chart") );

    // [3] change data of chart 1
    ptrChart->addSeries( CellRange("A1:B3") );
    ptrChart->setAxisTitle( Chart::Left, QString("new left title") );
    ptrChart->setAxisTitle( Chart::Bottom, QString("new bottom title") );
    ptrChart->setChartTitle( QString("new hello chart") );

    if ( !output.saveAs("test2.xlsx") )
    {
        qDebug() << "Failed to save xlsx file.";
    }

    return 0;
}

from qxlsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.