是Kendo UI angular的新功能, 我必须自定义条形图,其中每个条形都将具有多个颜色渐变。 剑道有可能达到吗?我的条形图已经融合开发,但是我发现用剑道很难达到同样的效果。
已附上我需要实现的图像以及我在kendo中的代码的图像。
我在剑道中的代码
<kendo-chart style="height: 317px;">
<kendo-chart-axis-defaults [majorGridLines]="{ visible : false}">
</kendo-chart-axis-defaults>
<kendo-chart-series-defaults type="bar">
<kendo-chart-series-defaults-labels format="">
</kendo-chart-series-defaults-labels>
</kendo-chart-series-defaults>
<kendo-chart-category-axis >
<kendo-chart-category-axis-item [categories]="['jan','feb','mar','apr','may','jun','aug','set','oct','nov','dec']">
</kendo-chart-category-axis-item>
</kendo-chart-category-axis>
<kendo-chart-series>
<kendo-chart-value-axis>
<kendo-chart-value-axis-item [line]="{visible:false}" labels="false">
</kendo-chart-value-axis-item>
</kendo-chart-value-axis>
<kendo-chart-series-item
type="column"
[color]="pointColor"
[gap]="10"
[stack]="true"
[data]="['1000','0','200','2000','1500','1000','0','200','2000','1500','3500','25']"
>
<kendo-chart-series-item-labels [content]="labelContent" rotation="90" [position]="end" >
</kendo-chart-series-item-labels>
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
答案 0 :(得分:0)
要获得渐变效果,可以使用系列属性overlay。
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<kendo-chart>
<kendo-chart-title text="Units sold"></kendo-chart-title>
<kendo-chart-category-axis>
<kendo-chart-category-axis-item [categories]="['Q1', 'Q2', 'Q3', 'Q4']">
</kendo-chart-category-axis-item>
</kendo-chart-category-axis>
<kendo-chart-series>
<kendo-chart-series-item type="bar" [gap]="2" [spacing]=".25" [data]="[100, 123, 234, 343]" [overlay]="{gradient: 'roundedBevel'}">
</kendo-chart-series-item>
<kendo-chart-series-item type="bar" [data]="[120, 67, 231, 196]" [overlay]="{gradient: 'glass'}" >
</kendo-chart-series-item>
<kendo-chart-series-item type="bar" [data]="[45, 124, 189, 143]" [overlay]="{gradient: 'none'}">
</kendo-chart-series-item>
<kendo-chart-series-item type="bar" [data]="[87, 154, 210, 215]" [overlay]="{gradient: 'sharpBevel'}">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
`
})
export class AppComponent {}
也遇到了这个demo,用于创建自定义线性渐变。请参考下面的代码,我以创建线性梯度柱形图为例。
import { Component } from '@angular/core';
import { Surface, Path, Text, Group, Layout, LinearGradient, GradientOptions, ShapeOptions } from '@progress/kendo-drawing';
import { Arc as DrawingArc, GradientStop } from '@progress/kendo-drawing';
import { Arc, Rect, ArcOptions } from '@progress/kendo-drawing/geometry';
function createColumn(rect, color) {
const origin = rect.origin;
const bottomRight = rect.bottomRight();
const gradient = new LinearGradient(<GradientOptions>{
stops: [new GradientStop(0, "#98FB98", 1),
new GradientStop(0.5, color, 1)]
});
const path = Path.fromRect(rect, <ShapeOptions>{
fill: gradient,
stroke: {
color: color,
width: 1
}
});
const group = new Group();
group.append(path);
return group;
}
@Component({
selector: 'my-app',
template: `
<kendo-chart [seriesDefaults]="chartConfig.seriesDefaults" >
<kendo-chart-title text="Units sold"></kendo-chart-title>
<kendo-chart-category-axis>
<kendo-chart-category-axis-item [categories]="['Q1', 'Q2', 'Q3', 'Q4']">
</kendo-chart-category-axis-item>
</kendo-chart-category-axis>
<kendo-chart-series>
<kendo-chart-series-item type="bar" [gap]="2" [spacing]=".25" [data]="[100, 123, 234, 343]" color="#008852">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
`
})
export class AppComponent {
public chartConfig = {
seriesDefaults: {
type: 'column',
visual: function (e) {
return createColumn(e.rect, e.options.color);
}
}
};
}
答案 1 :(得分:0)
查看您的图表,我觉得可以通过100% stacked column chart来实现,您可以获取彩色和灰色部分的数据。 然后使用可以显示并带有rotation的label属性。
<script>
$("#chart").kendoChart({
series: [ {
labels: {
visible: true,
position: "outsideEnd",
rotation: 270
},
data: [1, 2, 3]
}]
});
</script>
试图使用径向渐变和100%堆叠的条形图来获得类似的条形图
import { Component } from '@angular/core';
import { Surface, Path, Text, Group, Layout, LinearGradient, RadialGradient, GradientOptions, ShapeOptions } from '@progress/kendo-drawing';
import { Arc as DrawingArc, GradientStop } from '@progress/kendo-drawing';
import { Arc, Rect, ArcOptions } from '@progress/kendo-drawing/geometry';
function createColumn(rect, color) {
const origin = rect.origin;
const bottomRight = rect.bottomRight();
const radialgradient = new RadialGradient(<GradientOptions>{
center:[0.5, 0],
stops: [new GradientStop(0.5, color, 1),
new GradientStop(1, "#98FB98", 1)]
});
const path = Path.fromRect(rect, <ShapeOptions>{
fill: radialgradient,
stroke: {
color: color,
width: 1
}
});
const path1 = Path.fromRect(rect, <ShapeOptions>{
fill: {color: color},
stroke: {
color: color,
width: 1
}
});
const group = new Group();
if(color == "#eee"){
group.append(path1);
}
else{
group.append(path);
}
return group;
}
@Component({
selector: 'my-app',
template: `
<kendo-chart [seriesDefaults]="chartConfig.seriesDefaults" >
<kendo-chart-title text="Units sold"></kendo-chart-title>
<kendo-chart-category-axis>
<kendo-chart-category-axis-item [categories]="['Q1', 'Q2', 'Q3', 'Q4']">
</kendo-chart-category-axis-item>
</kendo-chart-category-axis>
<kendo-chart-series>
<kendo-chart-series-item type="column" [stack]="{ type: '100%' }" [gap]="2" [spacing]=".25" [data]="[100, 120, 250, 345]" color="#008852">
</kendo-chart-series-item>
<kendo-chart-series-item type="column" [data]="[400, 380, 250, 155]" color="#eee">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
`
})
export class AppComponent {
public chartConfig = {
seriesDefaults: {
visual: function (e) {
return createColumn(e.rect, e.options.color);
}
}
};
}