Is it possible to see the history of C# Lines of Code metric

Hello

I want to see the history of the C# Lines of Code metric.

I navigate to:

Main Branch > Measures > Size > Lines of Code

Here I can see the breakdown of Lines of Code by language - for my purposes I am only interesting in the C# Lines of Code metric.

If I click on the “See history” I can see the history of the Total Lines of Code metric in a graph. Is there any way of getting this information for the C# Lines of Code metric?

Hey there.

I was surprised to find out this information is available through the SonarQube Cloud API! You can view the history of the ncloc_language_distribution metric using GET api/measures/search_history, like this:

https://sonarcloud.io/api/measures/search_history?component=sonaranalyzer-dotnet&metrics=ncloc_language_distribution

{
  "paging": {
    "pageIndex": 1,
    "pageSize": 100,
    "total": 14
  },
  "measures": [
    {
      "metric": "ncloc_language_distribution",
      "history": [
        {
          "date": "2024-08-15T05:56:17+0000",
          "value": "cs=81360;xml=8478"
        },
        {
          "date": "2024-08-22T09:16:17+0000",
          "value": "cs=81424;xml=8463"
        },
        {
          "date": "2024-12-18T09:37:09+0000",
          "value": "cs=71473;web=47410;xml=8453"
        },
        {
          "date": "2025-01-10T14:30:20+0000",
          "value": "cs=71517;web=48390;xml=8453"
        },
        {
          "date": "2025-01-29T00:38:41+0000",
          "value": "cs=71540;web=48390;xml=8453"
        },
        {
          "date": "2025-02-28T00:39:42+0000",
          "value": "cs=71211;web=48638;xml=8453"
        },
        {
          "date": "2025-03-27T00:43:49+0000",
          "value": "cs=71235;web=48638;xml=8739"
        },
        {
          "date": "2025-04-04T00:42:43+0000",
          "value": "cs=71241;web=48638;xml=8739"
        },
        {
          "date": "2025-04-08T00:41:30+0000",
          "value": "cs=71272;web=48638;xml=8739"
        },
        {
          "date": "2025-04-18T00:42:55+0000",
          "value": "cs=71291;web=48638;xml=8739"
        },
        {
          "date": "2025-04-26T00:42:16+0000",
          "value": "cs=71401;web=48638;xml=8739"
        },
        {
          "date": "2025-04-30T00:43:55+0000",
          "value": "cs=71389;web=48642;xml=8739"
        },
        {
          "date": "2025-05-02T00:43:54+0000",
          "value": "cs=71656;web=48787;xml=8739"
        },
        {
          "date": "2025-05-03T00:43:18+0000",
          "value": "cs=71856;web=48787;xml=8739"
        }
      ]
    }
  ]
}

Just replace component=sonaranalyzer-dotnet with your project’s actual component key. The ncloc_language_distribution metric gives you the breakdown of lines of code by language over time, including C#.

I think this is really cool info and should definitely be exposed more directly in the UI! I’ve made an internal request to see if we can make that happen.