У меня есть такие столбцы:
[{"Year":"2004","Column":"Lower than 2.50","Amount":"23.8","Percent":"24%","Order":1},{"Year":"2008","Column":"Lower than 2.50","Amount":"24.9","Percent":"25%","Order":1},{"Year":"2012","Column":"Lower than 2.50","Amount":"24.3","Percent":"24%","Order":1},{"Year":"2004","Column":"2.50 - 2.99","Amount":"20.5","Percent":"21%","Order":2},{"Year":"2008","Column":"2.50 - 2.99","Amount":"19.9","Percent":"20%","Order":2},{"Year":"2012","Column":"2.50 - 2.99","Amount":"20.5","Percent":"21%","Order":2},{"Year":"2004","Column":"3.00 - 3.49","Amount":"26.5","Percent":"27%","Order":3},{"Year":"2008","Column":"3.00 - 3.49","Amount":"26.0","Percent":"26%","Order":3},{"Year":"2012","Column":"3.00 - 3.49","Amount":"26.2","Percent":"26%","Order":3},{"Year":"2004","Column":"3.50 or higher","Amount":"29.2","Percent":"29%","Order":4},{"Year":"2008","Column":"3.50 or higher","Amount":"29.2","Percent":"29%","Order":4},{"Year":"2012","Column":"3.50 or higher","Amount":"29.1","Percent":"29%","Order":4}]
Я хочу, чтобы цвет диаграммы соответствовал порядку, но это не так.
var myChart = new dimple.chart(svg, data);
/* var order = [],
i,
x,
chart = new dimple.chart(svg, data);
for (i = 0; i < data.length; i += 1) {
if (order.indexOf(data[i]["Column"]) === -1) {
order.push(data[i]["Column"]);
}
} */
myChart.setBounds(100 + ((options.chartCount - 1) * groupswidth), 30, groupswidth, 240);
// myChart.setBounds(60, 30, 210, 240);
myChart.defaultColors = chartOptions.colors;
// myChart.addCategoryAxis("x", ["Price Tier", "Channel"]);
var myXAxis = myChart.addCategoryAxis("x", ["Order", "Year", "Column", "Order"]);
myXAxis.title = options.yAxisTitle;
myXAxis.addGroupOrderRule(["Lower than 2.50", "2.50 - 2.99", "3.00 - 3.49", "3.50 or higher"]);
// myXAxis.addGroupOrderRule("Order", true);
// myXAxis.addGroupOrderRule("Year");
// alert('b');
// myChart.addMeasureAxis("y", "Unit Sales");
var myYAxis = '';
if (workspaceType == 'average')
{
myYAxis = myChart.addMeasureAxis("y", "Amount");
}
else
{
myYAxis = myChart.addMeasureAxis("y", "Percent");
}
myYAxis.showGridlines = true;
myYAxis.overrideMax = yaxis;
myYAxis.title = "";
myYAxis.tickFormat = d3.format(",");
var mySeries = myChart.addSeries("Column", dimple.plot.bar);
// myChart.addLegend(65, 10, 510, 20, "right");
// if (options.chartCount == options.finishChartCount)
if (options.chartCount == 1)
{
var myLegend = myChart.addLegend(100, 345, (options.chartCount * groupswidth), 30, "left");
/* myLegend._getEntries = function () {
var entries = [];
if (this.series) {
this.series.forEach(function (series) {
var data = series._positionData;
data.forEach(function (row) {
var index = -1,
j,
field = ((series.plot.grouped && !series.x._hasCategories() && !series.y._hasCategories() && row.aggField.length < 2 ? "All" : row.aggField.slice(-1)[0]));
for (j = 0; j < entries.length; j += 1) {
if (entries[j].key === field) {
index = j;
break;
}
}
if (index === -1 && series.chart._assignedColors[field]) {
entries.push({
key: field,
fill: series.chart._assignedColors[field].fill,
stroke: series.chart._assignedColors[field].stroke,
opacity: series.chart._assignedColors[field].opacity,
series: series,
aggField: row.aggField
});
index = entries.length - 1;
}
});
}, this);
}
// PUT YOUR SORTING LOGIC HERE
// For example to sort numeric values ascending
entries.sort(function (a, b) { return parseFloat(a.key) - parseFloat(b.key); });
return entries;
}; */
}
Мне нужна помощь, чтобы убедиться, что порядок 1 отображается сначала в легенде и цвете и т. Д.