- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在同一张图表上生成 2 个具有独立 X 轴(类别)值的图表(阶跃线)。据我所知,最接近的是:
AmCharts.makeChart("price-level-compare",
{
type: "serial",
dataProvider:
[
{qty1: 1, price1: 2.3, qty2: 1, price2: 3.6},
{qty1: 2, price1: 2.2, qty2: 5, price2: 3.3},
{qty1: 10, price1: 1.97,qty2: 10, price2: 3.1},
{qty1: 100, price1: 1.54,qty2: 200,price2: 1.1},
{qty1: 500, price1: 1.2, qty2: 300,price2: 1.0}
],
graphs: [{
"id":"g1",
"type": "step",
"lineThickness": 2,
"bullet":"square",
"bulletAlpha":0,
"bulletSize":4,
"bulletBorderAlpha":0,
"valueField": "price1"
},{
"id":"g2",
"type": "step",
"lineThickness": 2,
"bullet":"square",
"bulletAlpha":0,
"bulletSize":4,
"bulletBorderAlpha":0,
"valueField": "price2"
}],
"categoryField": "qty1"
}
);
它产生了这个不正确的图表:
我不知道如何指定另一个将“qty2”命名为“price2”值的 X 轴值的“categoryField”。
最佳答案
系列图表不支持多个类别字段。
鉴于您的数据是数字数据,XY 图表更适合。只需设置每个图表的 xField
和 yField
指向数据中的适当值。
graphs: [
{
id: "g1",
type: "step",
lineThickness: 2,
bullet: "square",
bulletAlpha: 0,
bulletSize: 4,
bulletBorderAlpha: 0,
xField: "qty1",
yField: "price1"
},
{
id: "g2",
type: "step",
lineThickness: 2,
bullet: "square",
bulletAlpha: 0,
bulletSize: 4,
bulletBorderAlpha: 0,
xField: "qty2",
yField: "price2"
}
下面的演示。
AmCharts.makeChart("chartdiv", {
type: "xy",
dataProvider: [
{ qty1: 1, price1: 2.3, qty2: 1, price2: 3.6 },
{ qty1: 2, price1: 2.2, qty2: 5, price2: 3.3 },
{ qty1: 10, price1: 1.97, qty2: 10, price2: 3.1 },
{ qty1: 100, price1: 1.54, qty2: 200, price2: 1.1 },
{ qty1: 500, price1: 1.2, qty2: 300, price2: 1.0 }
],
graphs: [
{
id: "g1",
type: "step",
lineThickness: 2,
bullet: "square",
bulletAlpha: 0,
bulletSize: 4,
bulletBorderAlpha: 0,
xField: "qty1",
yField: "price1"
},
{
id: "g2",
type: "step",
lineThickness: 2,
bullet: "square",
bulletAlpha: 0,
bulletSize: 4,
bulletBorderAlpha: 0,
xField: "qty2",
yField: "price2"
}
]
});
html, body {
width: 100%;
height: 100%;
margin: 0px;
}
#chartdiv {
width: 100%;
height: 100%;
}
<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/xy.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>
不幸的是,不支持步骤线,所以这是您在 v3 中可以做的最好的事情。
v4 的 XY 图表可以处理具有 XY 数值的阶梯线。您可以创建一个 StepLineSeries
并为您的 X 和 Y 值设置 valueY
和 valueX
属性
// Create series
var series1 = chart.series.push(new am4charts.StepLineSeries());
series1.dataFields.valueX = "qty1";
series1.dataFields.valueY = "price1";
series1.strokeWidth = 2;
var bullet1 = series1.bullets.push(new am4charts.Bullet());
var square = bullet1.createChild(am4core.Rectangle);
square.width = 10;
square.height = 10;
square.horizontalCenter = "middle";
square.verticalCenter = "middle";
bullet1.tooltipText = "Price: {valueX}\nQty: {valueY}";
//repeat for your second series
完整演示如下:
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
chart.data = [
{ qty1: 1, price1: 2.3, qty2: 1, price2: 3.6 },
{ qty1: 2, price1: 2.2, qty2: 5, price2: 3.3 },
{ qty1: 10, price1: 1.97, qty2: 10, price2: 3.1 },
{ qty1: 100, price1: 1.54, qty2: 200, price2: 1.1 },
{ qty1: 500, price1: 1.2, qty2: 300, price2: 1.0 }
];
// Create axes
var xAxis = chart.xAxes.push(new am4charts.ValueAxis());
xAxis.renderer.minGridDistance = 40;
// Create value axis
var yAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
var series1 = chart.series.push(new am4charts.StepLineSeries());
series1.dataFields.valueX = "qty1";
series1.dataFields.valueY = "price1";
series1.strokeWidth = 2;
var bullet1 = series1.bullets.push(new am4charts.Bullet());
var square = bullet1.createChild(am4core.Rectangle);
square.width = 10;
square.height = 10;
square.horizontalCenter = "middle";
square.verticalCenter = "middle";
bullet1.tooltipText = "Price: {valueX}\nQty: {valueY}";
var series2 = chart.series.push(new am4charts.StepLineSeries());
series2.dataFields.valueX = "qty2";
series2.dataFields.valueY = "price2";
var bullet2 = series2.bullets.push(new am4charts.CircleBullet());
var square2 = bullet2.createChild(am4core.Rectangle);
square2.width = 10;
square2.height = 10;
square2.horizontalCenter = "middle";
square2.verticalCenter = "middle";
bullet2.tooltipText = "Price: {valueX}\nQty: {valueY}";
html, body {
width: 100%;
height: 100%;
margin: 0;
}
#chartdiv {
width: 100%;
height: 100%;
}
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>
可以找到有关 v4 XY 图表的更多信息 here .
关于javascript - Amcharts v3 多分类步进图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55229327/
有没有办法在 D 范围内创建一个步骤?例如,在 python 中, 范围(1、10、2)给我 [1, 3, 5, 7, 9] 1 .. 10 以内的所有赔率 有没有办法在 D 中使用
我在 javascript 和 css(没有 jquery 或其他任何东西)中的幻灯片作业有问题。 此幻灯片应该有两种模式,一种是 i) 自动显示图片,另一种是 ii) 手动更改它们。该按钮应分别更改
我有一个在堆栈上声明的结构。这是结构的样子: struct MyStruct { int integer; std::vector booleanVector; }; 当我使用 gdb
我的容器进入第一行,但是当 float 导致第二行开始时,第二行没有进入。如何防止踩踏? HTML echo "". $row["FirstName"]. "" . $day_month .""; C
我们在 VMWare 中运行 Linux Debian。使用 gdb 调试时,如果尝试跨过 memset/memcmp/strcmp 等...,gdb 会返回以下错误: Cannot find bou
我是一名优秀的程序员,十分优秀!