Menu

Change X axis to category in Bar Chart

2021-08-18
2021-09-29
  • Leonardo Pollock

    Hi, Im having a little trouble trying to change the X axis in bar chart. I posted 3 screenshots: one of the data Im using, one of the chart the code is giving me and the other one( with the blue columns) is the one that I wanna create. I just wanna put the "date" in the bottom of the bar. Heres my code:

    CChartsheet & chartSheet1 = book.AddChartSheet("Grafico Barras", CHART_BAR);
        CChart::Series ser1;
        ser1.catAxisFrom=CellCoord(15,2);
        ser1.catAxisTo=CellCoord(15,5);
        ser1.catSheet = &sheet1;
    
        ser1.valAxisFrom=CellCoord(23,2);
        ser1.valAxisTo=CellCoord(23, 5);
        ser1.valSheet = &sheet1;
    
        ser1.title = "Grafico";
    
        chartSheet1.Chart().AddSeries(ser1);
    
        CChart::Series ser2 = ser1;
    
        book.SetActiveSheet( chartSheet1 );
    
        pName.Replace("\\","\\\\");
        book.Save(pName.GetString())
    

    Edit: I tried using chartSheet1.Chart().SetXAxisToCat(false); before chartSheet1.Chart().AddSeries(ser1);, but it didnt work out

     

    Last edit: Leonardo Pollock 2021-08-18
  • Alexandr Belyak

    Alexandr Belyak - 2021-08-18

    Hi, thanks for the detailed description of the problem.
    This requires a special axis category - the date axis.
    Unfortunately, the library does not currently support this.
    I can try adding such an axis. But it will take more than one day.

     
  • Leonardo Pollock

    Thanks for the response and for the amazing library. I would really appreciate that. Take as long as you need :) .

     
  • Alexandr Belyak

    Alexandr Belyak - 2021-08-24

    Hi,
    Please check the latest version of the library from the attachment.
    You need a function call:

    chartSheet1.Chart().SetXAxisType( CChart::EAxisType::AXIS_DATE );
    

    You may also find this function useful:

    chartSheet1.Chart().SetXAxisFormatCode( "dd\\.m" );
    

    Axis markers have also been added. Check out the new example "MixedLineAndBarChart.cpp".
    Thanks for waiting :-)

     
  • Leonardo Pollock

    Thanks a lot. I let the project rest, I thought you would take a little more time XD.

     
  • Alexandr Belyak

    Alexandr Belyak - 2021-09-29

    Was happy to help. I also thought it would take a lot of time :-)

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.