我使用 ChartJS 创建了一个饼图。
现在我想创建一个单击处理程序,在其中我可以获取已创建的图表部分的标签和值。我该如何实现这一目标?
let my_chart = new Chart('tot_pop_chart', {
type: 'pie',
data: {
labels: ['NSW', 'VIC', 'QSD', 'SA', 'WA', 'TAS', 'NT', 'ACT'],
datasets: [{
data: [1, 2, 3, 4, 5, 6, 7, 8],
backgroundColor: ['rgba(63, 75, 59, 1)', 'rgba(242, 246, 208, 1)', 'rgba(197, 123, 87, 1)', 'rgba(118, 159, 182, 1)', 'rgba(58, 110, 165, 1)', 'rgba(88, 12, 31, 1)', 'rgba(157, 172, 255, 1)', 'rgba(122, 48, 108, 1)']
}
]
},
options: {
animation: {},
plugins: {
legend: {
display: true, …Run Code Online (Sandbox Code Playgroud) 在熊猫中,我想在整个数据框中搜索特定值并返回其行和列索引。
例如:
apple pear orange banana
cat 1 2 3 4
dog 5 6 7 8
fish 9 10 11 12
bird 13 14 15 16
Run Code Online (Sandbox Code Playgroud)
输入:10
输出:鱼,梨
假设我有如下定义的类型 StrInt
type StrInt = (String, Int)
toStrInt:: Str -> Int -> StrInt
toStrInt str int = (str, int)
Run Code Online (Sandbox Code Playgroud)
我希望 Show 函数如下工作:输入:show (toStrInt "Hello", 123)
输出:"Hello123"
我试图定义 show 如下:
instance Show StrInt where
show (str, int) = (show str) ++ (show int)
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:
Illegal instance declaration for ‘Show StrInt’
(All instance types must be of the form (T t1 ... tn)
where T is not a synonym.
Use TypeSynonymInstances if you want to disable this.)
In the instance …Run Code Online (Sandbox Code Playgroud)