小编Ada*_*uck的帖子

ChartJS:datalabels:显示Pie piece中的百分比值

我有一个带有四个标签的饼图:

var data = [{
    data: [50, 55, 60, 33],
    labels: ["India", "China", "US", "Canada"],
    backgroundColor: [
        "#4b77a9",
        "#5f255f",
        "#d21243",
        "#B27200"
    ],
    borderColor: "#fff"
}];
Run Code Online (Sandbox Code Playgroud)

使用chartjs-plugin-datalabels插件我想用下面的代码显示每个Pie片中的百分比值:

formatter: (value, ctx) => {

        let datasets = ctx.chart.data.datasets;

        if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
            let sum = 0;
            datasets.map(dataset => {
                sum += dataset.data[ctx.dataIndex];
            });
            let percentage = Math.round((value / sum) * 100) + '%';
            return percentage;
        } else {
            return percentage;
        }
    },
    color: '#fff',
}
Run Code Online (Sandbox Code Playgroud)

我获得了所有馅饼的100%价值,而不是相应的百分比.这是JSFiddle(https://jsfiddle.net/kingBethal/a1Lvn4eb/7/)

javascript charts chart.js

9
推荐指数
5
解决办法
2万
查看次数

Dapper 无法将 SQL uniqueidentifier 类型读取为字符串

我有以下课程:

public class User
    {
        public string Id { get; set; }
        public string UserName { get; set; }
        public string DisplayName { get; set; }
        public DateTime RegistrationDateTime { get; set; }
        public DateTime LastLoginDateTime { get; set; }
        public bool IsAdmin { get; set; }

        public IEnumerable<Session> Sessions { get; set; }

        public class Session
        {
            public string Id { get; set; }
            public string UserId { get; set; }
            public User User { get; set; }
            public …
Run Code Online (Sandbox Code Playgroud)

c# sql-server dapper

6
推荐指数
1
解决办法
6838
查看次数

删除 NuGet 源(如果存在)

我正在尝试检测源是否已添加到配置文件中。如果已添加,我想将其删除。棘手的部分是我最初不知道源的名称,但知道路径。

使用nuget sources list -configfile C:\Temp\NuGet.Config我能够识别已添加的源,但这会返回一个字符串。

如何根据源路径识别源是否已添加并提取源名称以便将其删除?

一些伪代码:

nuget sources add -name "example.com" -source "https://nuget.example.com/nuget" -username "example" -password "example" -storepasswordincleartext -configfile C:\Temp\NuGet.Config

if source exists with path 'https://nuget.example.com/nuget':
    remove source
Run Code Online (Sandbox Code Playgroud)

powershell nuget

6
推荐指数
1
解决办法
3252
查看次数

带有 Linq 表达式的 IQueryable 导致 NullReferenceException

以下函数导致 NullReferenceException,因为它正在引用m.tags尚未在 JSON 对象中声明的 。这是故意的。我需要查询所有没有现有tags对象的JSON对象。

选择下一步

TweetModel tweet = client
    .CreateDocumentQuery<TweetModel>( UriFactory.CreateDocumentCollectionUri( databaseName, collectionName), queryOptions )
    .Where( m => m.tags == null )
    .ToList()
    .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

示例文档

{
  "timestamp": "2017-07-05T19:31:18.918Z",
  "topic": "Trump",
  "score": "1",
  "sentiment": "positive",
  "text": "@gjacquette @travi44 @WSJ Where did I say trump shouldn't hire a lawyer? I said the fact his lawyers are hiring law… ",
  "id": "882683325495816192",
  "retweet_count": 0,
  "time_zone": null,
  "lang": "en",
  "screen_name": "bernielove1969"
}
Run Code Online (Sandbox Code Playgroud)

tags对象声明空值解决了异常,所以我确定这是问题所在,我只是不确定如何解决它。

在过去的几个小时内,我尝试修改m => m.tags …

c# linq lambda

1
推荐指数
1
解决办法
1470
查看次数

标签 统计

c# ×2

chart.js ×1

charts ×1

dapper ×1

javascript ×1

lambda ×1

linq ×1

nuget ×1

powershell ×1

sql-server ×1